Skip to content

Commit a797010

Browse files
Added missing assertions on the increment Store method
1 parent fd2aa65 commit a797010

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

test/stores/store_aggregated_ip.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'mocha'
2+
import { assert } from 'chai'
23

34
import { Pool } from 'pg'
45
import sinon, { SinonMock, SinonStub } from 'sinon'
@@ -56,20 +57,21 @@ describe('Postgres Store Aggregated IP', () => {
5657

5758
it('increment function should follow expected business logic', async () => {
5859
let pool = new Pool()
60+
let dbCount = 1
5961

6062
isSessionValidSpy.returns(true)
6163
query.onFirstCall().returns({
6264
rows: [
6365
{
64-
count: 1,
66+
count: dbCount,
6567
},
6668
],
6769
})
6870
let testStore = new PostgresStore({}, 'test')
6971
testStore.pool = pool
7072
testStore.session = newCreatedSession
7173

72-
await testStore.increment('key')
74+
let incrementCount = await testStore.increment('key')
7375
sinon.assert.callCount(isSessionValidSpy, 1)
7476
sinon.assert.calledWith(
7577
query,
@@ -81,6 +83,14 @@ describe('Postgres Store Aggregated IP', () => {
8183
`,
8284
['key', newCreatedSession.id],
8385
)
86+
assert.equal(incrementCount.totalHits, dbCount)
87+
assert.isTrue(
88+
(incrementCount.resetTime?.getMilliseconds() ||
89+
new Date().getMilliseconds()) -
90+
(newCreatedSession.expires_at?.getMilliseconds() ||
91+
new Date().getMilliseconds()) <
92+
10,
93+
)
8494
})
8595

8696
it('decrement function should follow expected business logic', async () => {

test/stores/store_individual_ip.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'mocha'
2+
import { assert } from 'chai'
23

34
import { Pool } from 'pg'
45
import sinon, { SinonMock, SinonStub } from 'sinon'
@@ -56,6 +57,7 @@ describe('Postgres Store Individual IP', () => {
5657

5758
it('increment function should follow expected business logic', async () => {
5859
let pool = new Pool()
60+
let dbCount = 1
5961

6062
isSessionValidSpy.returns(true)
6163
query.onFirstCall().returns({
@@ -65,15 +67,15 @@ describe('Postgres Store Individual IP', () => {
6567
query.onSecondCall().returns({
6668
rows: [
6769
{
68-
count: 1,
70+
count: dbCount,
6971
},
7072
],
7173
})
7274
let testStore = new PostgresStoreIndividualIP({}, 'test')
7375
testStore.pool = pool
7476
testStore.session = newCreatedSession
7577

76-
await testStore.increment('key')
78+
let incrementCount = await testStore.increment('key')
7779
sinon.assert.callCount(isSessionValidSpy, 1)
7880
sinon.assert.calledWith(
7981
query,
@@ -85,6 +87,14 @@ describe('Postgres Store Individual IP', () => {
8587
'SELECT count(id) AS count FROM rate_limit.individual_records WHERE key = $1 AND session_id = $2',
8688
['key', newCreatedSession.id],
8789
)
90+
assert.equal(incrementCount.totalHits, dbCount)
91+
assert.isTrue(
92+
(incrementCount.resetTime?.getMilliseconds() ||
93+
new Date().getMilliseconds()) -
94+
(newCreatedSession.expires_at?.getMilliseconds() ||
95+
new Date().getMilliseconds()) <
96+
10,
97+
)
8898
})
8999

90100
it('decrement function should follow expected business logic', async () => {

test/util/session_handler.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'mocha'
2-
import { assert, expect } from 'chai'
2+
import { assert } from 'chai'
33
import {
44
calculateNextResetTime,
55
getSession,

0 commit comments

Comments
 (0)