Skip to content

Commit da109bd

Browse files
committed
Test for trouble ticket caching load/store
1 parent ca7d380 commit da109bd

File tree

1 file changed

+49
-12
lines changed

1 file changed

+49
-12
lines changed

tests/google-sheets/load-cached-trouble-ticket-data.test.ts

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {loadCachedTroubleTicketData} from '../../src/load-cached-sheet-data';
22
import {getCachedSheetData} from '../../src/init-dependencies/google/get-cached-sheet-data';
33
import pino from 'pino';
44
import {ensureCachedSheetDataTableExists} from '../../src/init-dependencies/google/ensure-cached-sheet-data-table-exists';
5-
import {getRightOrFail} from '../helpers';
5+
import {getLeftOrFail, getRightOrFail} from '../helpers';
66
import {constructEvent, EventOfType} from '../../src/types/domain-event';
77
import {faker} from '@faker-js/faker';
88
import {initTestFramework, TestFramework} from '../read-models/test-framework';
@@ -91,19 +91,56 @@ describe('Load cached trouble ticket data', () => {
9191
},
9292
}),
9393
];
94-
beforeEach(async () => {
95-
await _cacheSheetData(
96-
timestamp,
97-
troubleTicketSheetId,
98-
pino({level: 'silent'}),
99-
trainingQuizResults
100-
);
94+
describe('Cache load with no store', () => {
95+
it('Check no responses are retrieved', async () => {
96+
getLeftOrFail(await _loadCachedTroubleTicket());
97+
const troubleTickets =
98+
framework.sharedReadModel.troubleTickets.getAll();
99+
expectTroubleTicketToMatchResponses([], troubleTickets);
100+
});
101101
});
102+
describe('Cache store + load', () => {
103+
beforeEach(async () => {
104+
await _cacheSheetData(
105+
timestamp,
106+
troubleTicketSheetId,
107+
pino({level: 'silent'}),
108+
trainingQuizResults
109+
);
110+
});
102111

103-
it('Check both responses are retrieved', async () => {
104-
getRightOrFail(await _loadCachedTroubleTicket());
105-
const troubleTickets = framework.sharedReadModel.troubleTickets.getAll();
106-
expectTroubleTicketToMatchResponses(trainingQuizResults, troubleTickets);
112+
it('Check both responses are retrieved', async () => {
113+
getRightOrFail(await _loadCachedTroubleTicket());
114+
const troubleTickets =
115+
framework.sharedReadModel.troubleTickets.getAll();
116+
expectTroubleTicketToMatchResponses(
117+
trainingQuizResults,
118+
troubleTickets
119+
);
120+
});
121+
});
122+
describe('Double store then cache load', () => {
123+
beforeEach(async () => {
124+
for (let i = 0; i < 2; i++) {
125+
await _cacheSheetData(
126+
timestamp,
127+
troubleTicketSheetId,
128+
pino({level: 'silent'}),
129+
trainingQuizResults
130+
);
131+
}
132+
});
133+
134+
it('Check both responses are retrieved', async () => {
135+
// Specifically interested we don't double-store.
136+
getRightOrFail(await _loadCachedTroubleTicket());
137+
const troubleTickets =
138+
framework.sharedReadModel.troubleTickets.getAll();
139+
expectTroubleTicketToMatchResponses(
140+
trainingQuizResults,
141+
troubleTickets
142+
);
143+
});
107144
});
108145
});
109146
});

0 commit comments

Comments
 (0)