Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
tests/ tests suites for business logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MiroBenicio committed Oct 4, 2023
1 parent 64d8992 commit e022d9b
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 43 deletions.
5 changes: 1 addition & 4 deletions __tests__/allRequirements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ import mockCheckPayout from "./__mocks__/mockCheckPayout";

describe("All Requirements Fullfilled", () => {
test("Test suite", () => {

const store = new ServiceStore();
const gmail = store.gmail as StateAccount;
expect(connectGmail(gmail)).toBe("P100");


const retailer = store.retailer as StateAccount;
expect(connectRetailer(retailer)).toBe("P100");

expect(fourWeeks(store.sync)).toBe(4);

expect(fiveReceipts(store.receipt)).toBe(5);


expect(
mockCheckPayout(
store.sync.countWeeks(new Date('09/27/2023')),
store.sync.countWeeks(new Date("09/27/2023")),
store.receipt.count(),
gmail.get().value,
retailer.get().value
Expand Down
38 changes: 38 additions & 0 deletions __tests__/lostWeekLoginDoesNotResetState.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { StateAccount } from "../src/service/store/state/state-account";
import { ServiceStore } from "../src/service/store";
import connectGmail from "./__fixtures__/connectGmail";
import connectRetailer from "./__fixtures__/connectRetailer";
import fiveReceipts from "./__fixtures__/fiveReceipts";
import mockCheckPayout from "./__mocks__/mockCheckPayout";

describe("User misses a weekly login", () => {
test("test suite", () => {
const store = new ServiceStore();
const gmail = store.gmail as StateAccount;
const retailer = store.retailer as StateAccount;

store.sync.add(new Date("09/05/2023"));
store.sync.add(new Date("09/12/2023"));
store.sync.add(new Date("09/24/2023"));
store.sync.add(new Date("10/01/2023"));
const count = store.sync.countWeeks(new Date("10/02/2023"));

expect(count).toBeLessThan(4);

expect(connectGmail(gmail)).toBe("P100");
expect(connectRetailer(retailer)).toBe("P100");
expect(fiveReceipts(store.receipt)).toBe(5);
expect(gmail.get().value).toBe("P100")
expect(retailer.get().value).toBe("P100")
expect(store.receipt.count()).toBe(5)

expect(
mockCheckPayout(
count,
store.receipt.count(),
gmail.get().value,
retailer.get().value
)
).toBeFalsy();
});
});
1 change: 0 additions & 1 deletion __tests__/userConnectsOnlyGmail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe("User connects Gmail but not Retailer Account", () => {

expect(fiveReceipts(store.receipt)).toBe(5);

//mock checkPayout
expect(
mockCheckPayout(
store.sync.countWeeks(new Date("09/27/2023")),
Expand Down
2 changes: 0 additions & 2 deletions __tests__/userConnectsOnlyRetailer.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { StateAccount } from "../src/service/store/state/state-account";
import { ServiceStore } from "../src/service/store";
import connectGmail from "./__fixtures__/connectGmail";
import fourWeeks from "./__fixtures__/fourWeeks";
import fiveReceipts from "./__fixtures__/fiveReceipts";
import mockCheckPayout from "./__mocks__/mockCheckPayout";
Expand All @@ -21,7 +20,6 @@ describe("User Connects Only a Retailer Account", () => {

expect(fiveReceipts(store.receipt)).toBe(5);

//mock checkPayout
expect(
mockCheckPayout(
store.sync.countWeeks(new Date("09/27/2023")),
Expand Down
2 changes: 0 additions & 2 deletions __tests__/userDisconnectRetailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import fiveReceipts from "./__fixtures__/fiveReceipts";
import fourWeeks from "./__fixtures__/fourWeeks";
import mockCheckPayout from "./__mocks__/mockCheckPayout";



describe('User disconnect Gmail', ()=>{
test("test suite", async ()=>{
const store = new ServiceStore()
Expand Down
64 changes: 31 additions & 33 deletions __tests__/userDoesNotShare5Receipts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,37 @@ import { StateAccount } from "../src/service/store/state/state-account";
import { ServiceStore } from "../src/service/store";
import connectGmail from "./__fixtures__/connectGmail";
import connectRetailer from "./__fixtures__/connectRetailer";
import fiveReceipts from "./__fixtures__/fiveReceipts";
import fourWeeks from "./__fixtures__/fourWeeks";
import mockCheckPayout from "./__mocks__/mockCheckPayout";

describe("User does not share 5 receipts", ()=>{
test("Test Suite", ()=>{
const store = new ServiceStore();

const gmail = store.gmail as StateAccount;
expect(connectGmail(gmail)).toBe("P100");


const retailer = store.retailer as StateAccount;
expect(connectRetailer(retailer)).toBe("P100");

expect(fourWeeks(store.sync)).toBe(4);

store.receipt.add('receipt1', new Date('09/05/2023'))
store.receipt.add('receipt2', new Date('09/12/2023'))
store.receipt.add('receipt3', new Date('09/12/2023'))
store.receipt.add('receipt4', new Date('09/19/2023'))

const receiptCount = store.receipt.count()

expect(receiptCount).toBe(4)

expect(
mockCheckPayout(
store.sync.countWeeks(new Date('09/27/2023')),
receiptCount,
gmail.get().value,
retailer.get().value
)
).toBeFalsy();
})
})
describe("User does not share 5 receipts", () => {
test("Test Suite", () => {
const store = new ServiceStore();

const gmail = store.gmail as StateAccount;
expect(connectGmail(gmail)).toBe("P100");

const retailer = store.retailer as StateAccount;
expect(connectRetailer(retailer)).toBe("P100");

expect(fourWeeks(store.sync)).toBe(4);

store.receipt.add("receipt1", new Date("09/05/2023"));
store.receipt.add("receipt2", new Date("09/12/2023"));
store.receipt.add("receipt3", new Date("09/12/2023"));
store.receipt.add("receipt4", new Date("09/19/2023"));

const receiptCount = store.receipt.count();

expect(receiptCount).toBe(4);

expect(
mockCheckPayout(
store.sync.countWeeks(new Date("09/27/2023")),
receiptCount,
gmail.get().value,
retailer.get().value
)
).toBeFalsy();
});
});
2 changes: 1 addition & 1 deletion __tests__/weeklyLoginMissed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("User misses a weekly login", () => {
const gmail = store.gmail as StateAccount;

expect(connectGmail(gmail)).toBe("P100");
//add a retailer account

const retailer = store.retailer as StateAccount;
expect(connectRetailer(retailer)).toBe("P100");

Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ module.exports = {
getRandomValues: (arr) => require("crypto").randomBytes(arr.length),
},
},
modulePathIgnorePatterns: ["<rootDir>/__tests__/__mocks__/*", "<rootDir>/__tests__/__fixtures__/*"]
}

0 comments on commit e022d9b

Please sign in to comment.