diff --git a/controller/store/bandwidthLimitJournal_test.go b/controller/store/bandwidthLimitJournal_test.go index 254cff92..449a42d6 100644 --- a/controller/store/bandwidthLimitJournal_test.go +++ b/controller/store/bandwidthLimitJournal_test.go @@ -61,3 +61,35 @@ func TestBandwidthLimitJournal(t *testing.T) { assert.Equal(t, int64(10240), latestJe.RxBytes) assert.Equal(t, int64(20480), latestJe.TxBytes) } + +func TestFindAllBandwidthLimitJournal(t *testing.T) { + str, err := Open(&Config{Path: ":memory:", Type: "sqlite3"}) + assert.Nil(t, err) + assert.NotNil(t, str) + + trx, err := str.Begin() + assert.Nil(t, err) + assert.NotNil(t, trx) + + acctId1, err := str.CreateAccount(&Account{Email: "nobody@nowehere.com", Salt: "salt1", Password: "password1", Token: "token1", Limitless: false, Deleted: false}, trx) + assert.Nil(t, err) + + _, err = str.CreateBandwidthLimitJournalEntry(&BandwidthLimitJournalEntry{AccountId: acctId1, Action: WarningLimitAction, RxBytes: 2048, TxBytes: 4096}, trx) + assert.Nil(t, err) + _, err = str.CreateBandwidthLimitJournalEntry(&BandwidthLimitJournalEntry{AccountId: acctId1, Action: LimitLimitAction, RxBytes: 2048, TxBytes: 4096}, trx) + assert.Nil(t, err) + aljId13, err := str.CreateBandwidthLimitJournalEntry(&BandwidthLimitJournalEntry{AccountId: acctId1, Action: LimitLimitAction, RxBytes: 8192, TxBytes: 10240}, trx) + assert.Nil(t, err) + + acctId2, err := str.CreateAccount(&Account{Email: "someone@somewhere.com", Salt: "salt2", Password: "password2", Token: "token2", Limitless: false, Deleted: false}, trx) + assert.Nil(t, err) + + aljId21, err := str.CreateBandwidthLimitJournalEntry(&BandwidthLimitJournalEntry{AccountId: acctId2, Action: WarningLimitAction, RxBytes: 2048, TxBytes: 4096}, trx) + assert.Nil(t, err) + + aljs, err := str.FindAllLatestBandwidthLimitJournal(trx) + assert.Nil(t, err) + assert.Equal(t, 2, len(aljs)) + assert.Equal(t, aljId13, aljs[0].Id) + assert.Equal(t, aljId21, aljs[1].Id) +}