-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjest.setup.js
58 lines (54 loc) · 2.14 KB
/
jest.setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import prisma from "@/app/services/prisma";
import "@testing-library/jest-dom";
/**
* Function to get row counts for all tables in the database.
* @returns {Promise<Object>} An object where keys are table names and values are row counts.
* TODO: How do we ensure we keep this in sync with our DB?
*/
async function getRowCounts() {
return {
User: await prisma.user.count(),
Wallet: await prisma.wallet.count(),
Email: await prisma.email.count(),
Question: await prisma.question.count(),
QuestionOption: await prisma.questionOption.count(),
Tag: await prisma.tag.count(),
QuestionTag: await prisma.questionTag.count(),
Deck: await prisma.deck.count(),
UserDeck: await prisma.userDeck.count(),
DeckQuestion: await prisma.deckQuestion.count(),
QuestionAnswer: await prisma.questionAnswer.count(),
ChompResult: await prisma.chompResult.count(),
FungibleAssetTransactionLog:
await prisma.fungibleAssetTransactionLog.count(),
RevealNft: await prisma.revealNft.count(),
Stack: await prisma.stack.count(),
Banner: await prisma.banner.count(),
MysteryBox: await prisma.mysteryBox.count(),
MysteryBoxTrigger: await prisma.mysteryBoxTrigger.count(),
MysteryBoxPrize: await prisma.mysteryBoxPrize.count(),
MysteryBoxAllowlist: await prisma.mysteryBoxAllowlist.count(),
ChainTx: await prisma.chainTx.count(),
CampaignMysteryBox: await prisma.campaignMysteryBox.count(),
CampaignMysteryBoxAllowlist:
await prisma.campaignMysteryBoxAllowlist.count(),
CreditPack: await prisma.creditPack.count(),
};
}
beforeAll(async () => {
global.initialRowCounts = await getRowCounts();
//console.log(
// "Shared beforeAll: Running before all tests in this file",
// global.initialRowCounts,
//);
});
afterAll(async () => {
const finalRowCounts = await getRowCounts();
for (const [table, initialCount] of Object.entries(global.initialRowCounts)) {
if (finalRowCounts[table] !== initialCount) {
console.error("InitialCount", global.initialRowCounts);
console.error("FinalCount", finalRowCounts);
throw new Error(`Row count mismatch for table ${table}`);
}
}
});