This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from tiki/testing/unit-test-the-business-stat…
…e-logic Testing/unit test the business state logic
- Loading branch information
Showing
21 changed files
with
6,129 additions
and
2,133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { StateAccount } from "../../src/service/store/state/state-account" | ||
import { Account, accountTypes } from "@mytiki/capture-receipt-capacitor"; | ||
import { ServiceStore } from "../../src/service/store" | ||
|
||
export default function connectGmail (storeGmail: StateAccount): string { | ||
const account: Account = { | ||
username: "[email protected]", | ||
type: accountTypes.index.get("GMAIL")!, | ||
isVerified: true | ||
} | ||
//checking the email state | ||
storeGmail.update([account]) | ||
const gmailStatus: string = storeGmail.get().value | ||
return gmailStatus | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { StateAccount } from "../../src/service/store/state/state-account" | ||
import { Account, accountTypes } from "@mytiki/capture-receipt-capacitor"; | ||
import { ServiceStore } from "../../src/service/store" | ||
|
||
export default function connectRetailer (retailerStore: StateAccount): string { | ||
const account: Account = { | ||
username: "[email protected]", | ||
type: accountTypes.index.get("AMAZON")!, | ||
isVerified: true | ||
} | ||
//checking the email state | ||
retailerStore.update([account]) | ||
const gmailStatus: string = retailerStore.get().value | ||
return gmailStatus | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { StateReceipt } from "../../src/service/store/state"; | ||
export default function fiveReceipts (receiptState: StateReceipt): number { | ||
// add 5 receipts | ||
receiptState.add('receipt1', new Date('09/05/2023')) | ||
receiptState.add('receipt2', new Date('09/12/2023')) | ||
receiptState.add('receipt3', new Date('09/12/2023')) | ||
receiptState.add('receipt4', new Date('09/19/2023')) | ||
receiptState.add('receipt5', new Date('09/19/2023')) | ||
|
||
//check the receipt state | ||
const receiptCount = receiptState.count() | ||
return receiptCount | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { StateSync } from "../../src/service/store/state"; | ||
export default function fourWeeks (stateSync: StateSync): number{ | ||
// add the 4 weeks logins | ||
stateSync.add(new Date('09/05/2023')) | ||
stateSync.add(new Date('09/12/2023')) | ||
stateSync.add(new Date('09/19/2023')) | ||
stateSync.add(new Date('09/26/2023')) | ||
const count = stateSync.countWeeks(new Date('09/27/2023')) | ||
return count | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
let localStorageMock = (function() { | ||
var store = {}; | ||
return { | ||
getItem: function(key) { | ||
return store[key]; | ||
}, | ||
setItem: function(key, value) { | ||
store[key] = value.toString(); | ||
}, | ||
clear: function() { | ||
store = {}; | ||
}, | ||
removeItem: function(key) { | ||
delete store[key]; | ||
} | ||
}; | ||
})(); | ||
Object.defineProperty(window, 'localStorage', { value: localStorageMock }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BulletState } from "../../src/components/bullet/bullet-state"; | ||
|
||
export default function mockCheckPayout( | ||
sync: number, | ||
receipts: number, | ||
gmailState: string, | ||
retailerState: string | ||
): boolean { | ||
if ( | ||
gmailState === BulletState.P100 && | ||
retailerState === BulletState.P100 && | ||
sync >= 4 && | ||
receipts >= 5 | ||
) { | ||
return true | ||
} else return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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("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.receipt.count(), | ||
gmail.get().value, | ||
retailer.get().value | ||
) | ||
).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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"; | ||
|
||
describe("User connects Gmail but not Retailer Account", () => { | ||
test("test suite", async () => { | ||
const store = new ServiceStore(); | ||
const gmail = store.gmail as StateAccount; | ||
expect(connectGmail(gmail)).toBe("P100"); | ||
|
||
const retailer = store.retailer as StateAccount; | ||
await retailer.update([]) | ||
|
||
expect(fourWeeks(store.sync)).toBe(4); | ||
|
||
expect(fiveReceipts(store.receipt)).toBe(5); | ||
|
||
expect( | ||
mockCheckPayout( | ||
store.sync.countWeeks(new Date("09/27/2023")), | ||
store.receipt.count(), | ||
gmail.get().value, | ||
retailer.get().value | ||
) | ||
).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { StateAccount } from "../src/service/store/state/state-account"; | ||
import { ServiceStore } from "../src/service/store"; | ||
import fourWeeks from "./__fixtures__/fourWeeks"; | ||
import fiveReceipts from "./__fixtures__/fiveReceipts"; | ||
import mockCheckPayout from "./__mocks__/mockCheckPayout"; | ||
import connectRetailer from "./__fixtures__/connectRetailer"; | ||
|
||
describe("User Connects Only a Retailer Account", () => { | ||
test("test suite", async () => { | ||
const store = new ServiceStore(); | ||
const gmail = store.gmail as StateAccount; | ||
await gmail.update([]); | ||
|
||
expect(gmail.get().value).toBe("NULL"); | ||
|
||
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.receipt.count(), | ||
gmail.get().value, | ||
retailer.get().value | ||
) | ||
).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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 disconnect Gmail", () => { | ||
test("test suite", async () => { | ||
const store = new ServiceStore(); | ||
const gmail = store.gmail as StateAccount; | ||
expect(connectGmail(gmail)).toBe("P100"); | ||
|
||
await gmail.update([]); | ||
const gmailStatus = gmail.get().value; | ||
expect(gmailStatus).toBe("NULL"); | ||
|
||
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.receipt.count(), | ||
gmail.get().value, | ||
retailer.get().value | ||
) | ||
).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
import { StateAccount } from "../src/service/store/state/state-account" | ||
import { ServiceStore } from "../src/service/store" | ||
import connectRetailer from "./__fixtures__/connectRetailer" | ||
import connectGmail from "./__fixtures__/connectGmail"; | ||
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() | ||
const retailer = store.retailer as StateAccount | ||
expect(connectRetailer(retailer)).toBe('P100') | ||
|
||
await retailer.update([]) | ||
const retailerStatus = retailer.get().value | ||
expect(retailerStatus).toBe("NULL") | ||
|
||
const gmail = store.gmail as StateAccount | ||
expect(connectGmail(gmail)).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.receipt.count(), | ||
gmail.get().value, | ||
retailer.get().value | ||
) | ||
).toBeFalsy(); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 mockCheckPayout from "./__mocks__/mockCheckPayout"; | ||
|
||
describe("User misses a weekly login", () => { | ||
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(fiveReceipts(store.receipt)).toBe(5); | ||
|
||
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( | ||
mockCheckPayout( | ||
count, | ||
store.receipt.count(), | ||
gmail.get().value, | ||
retailer.get().value | ||
) | ||
).toBeFalsy(); | ||
}); | ||
}); |
Oops, something went wrong.