Last active
January 13, 2023 18:23
-
-
Save plourenco/140174076e3cb73a5c57ecf29819e8a5 to your computer and use it in GitHub Desktop.
Test creation of credix pass
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
it("test", async () => { | |
const org = new Organization(); | |
org.users = Promise.resolve([]); | |
org.compliances = []; | |
const { publicKey } = new Keypair(); | |
const user = new UserEntity(); | |
user.id = "1"; | |
user.organization = org; | |
user.publicKey = publicKey.toString(); | |
const marketClients = new Map(); | |
const marketClientMock = (name: string) => ({ | |
name, | |
fetchCredixPass: jest.fn(() => null), | |
issueCredixPass: jest.fn(() => ""), | |
}); | |
for (const i of ["1", "2"]) { | |
const terms = new TermsOfUse(); | |
terms.id = i; | |
const market = new Market(); | |
market.id = i; | |
market.name = `market ${i}`; | |
market.termsOfUse = terms; | |
const compliance = new Compliance(); | |
compliance.termsOfUse = terms; | |
compliance.market = market; | |
compliance.organization = org; | |
org.compliances.push(compliance); | |
marketClients.set(market.name, marketClientMock(market.name)); | |
} | |
jest.mock("dayjs", () => ({ | |
default: jest.fn(), | |
unix: jest.fn(), | |
})); | |
jest | |
.spyOn(client, "fetchMarket") | |
.mockImplementation((marketName: string) => marketClients.get(marketName)); | |
await service.addUserWithCredixPasses(org, user); | |
for (const [name, marketClient] of marketClients.entries()) { | |
expect(client.fetchMarket).toHaveBeenCalledWith(name); | |
expect(marketClient.fetchCredixPass).toHaveBeenCalledWith(publicKey); | |
// Instead of anything you can use a custom config | |
expect(marketClient.issueCredixPass).toHaveBeenCalledWith(publicKey, expect.anything()); | |
} | |
expect(service.addUserWithCredixPasses).resolves.toBeTruthy; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment