-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from systemli/Fix-fetching-Tickers-for-non-ad…
…min-Users 🐛 Fix fetching Tickers for non-admin Users
- Loading branch information
Showing
8 changed files
with
176 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,6 +361,82 @@ var _ = Describe("SqlStorage", func() { | |
}) | ||
}) | ||
|
||
Describe("FindTickersByUser", func() { | ||
var user = User{ | ||
Email: "[email protected]", | ||
IsSuperAdmin: false, | ||
} | ||
var admin User = User{ | ||
Email: "[email protected]", | ||
IsSuperAdmin: true, | ||
} | ||
var ticker Ticker = Ticker{ | ||
Users: []User{user}, | ||
} | ||
|
||
BeforeEach(func() { | ||
Expect(db.Create(&user).Error).ToNot(HaveOccurred()) | ||
Expect(db.Create(&admin).Error).ToNot(HaveOccurred()) | ||
Expect(db.Create(&ticker).Error).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("returns all tickers for admins", func() { | ||
tickers, err := store.FindTickersByUser(admin) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(tickers).To(HaveLen(1)) | ||
}) | ||
|
||
It("returns all tickers for users", func() { | ||
tickers, err := store.FindTickersByUser(user) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(tickers).To(HaveLen(1)) | ||
}) | ||
|
||
It("returns no tickers for users", func() { | ||
tickers, err := store.FindTickersByUser(User{ID: 2}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(tickers).To(BeEmpty()) | ||
}) | ||
}) | ||
|
||
Describe("FindTickerByUserAndID", func() { | ||
var user = User{ | ||
Email: "[email protected]", | ||
IsSuperAdmin: false, | ||
} | ||
var admin = User{ | ||
Email: "[email protected]", | ||
IsSuperAdmin: true, | ||
} | ||
var ticker = Ticker{ | ||
Users: []User{user}, | ||
} | ||
|
||
BeforeEach(func() { | ||
Expect(db.Create(&user).Error).ToNot(HaveOccurred()) | ||
Expect(db.Create(&admin).Error).ToNot(HaveOccurred()) | ||
Expect(db.Create(&ticker).Error).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("returns the ticker for admins", func() { | ||
ticker, err := store.FindTickerByUserAndID(admin, ticker.ID) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(ticker).ToNot(BeZero()) | ||
}) | ||
|
||
It("returns the ticker for users", func() { | ||
ticker, err := store.FindTickerByUserAndID(user, ticker.ID) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(ticker).ToNot(BeZero()) | ||
}) | ||
|
||
It("returns no ticker for users", func() { | ||
ticker, err := store.FindTickerByUserAndID(User{ID: 2}, ticker.ID) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(ticker).To(BeZero()) | ||
}) | ||
}) | ||
|
||
Describe("FindTickersByIDs", func() { | ||
It("returns the tickers with the given ids", func() { | ||
tickers, err := store.FindTickersByIDs([]int{1, 2}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters