This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
161 additions
and
151 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
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
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
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
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
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 |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import { RuntimeError, test, TestContext } from "../_gen/test.ts"; | ||
import { assertEquals, assertRejects } from "https://deno.land/[email protected]/assert/mod.ts"; | ||
import { | ||
assertEquals, | ||
assertRejects, | ||
} from "https://deno.land/[email protected]/assert/mod.ts"; | ||
import { faker } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
test ( | ||
"get balance for nonexistent user", | ||
async (ctx: TestContext) => { | ||
test( | ||
"get balance for nonexistent user", | ||
async (ctx: TestContext) => { | ||
const { balance } = await ctx.modules.currency.getBalance({ | ||
userId: "00000000-0000-0000-0000-000000000000", | ||
}); | ||
assertEquals(balance, 0); | ||
} | ||
) | ||
|
||
assertEquals(balance, 0); | ||
}, | ||
); | ||
|
||
test( | ||
"withdraw more than balance", | ||
|
@@ -26,101 +29,104 @@ test( | |
amount: 100, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.withdraw({ userId: user.id, amount: 150 }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "NOT_ENOUGH_FUNDS"); | ||
} | ||
}, | ||
); | ||
|
||
test( | ||
"withdraw negative amount", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.withdraw({ userId: user.id, amount: -100 }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
} | ||
) | ||
"withdraw negative amount", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.withdraw({ userId: user.id, amount: -100 }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
}, | ||
); | ||
|
||
test( | ||
"withdraw Infinity", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.withdraw({ userId: user.id, amount: Infinity }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
} | ||
) | ||
"withdraw Infinity", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.withdraw({ | ||
userId: user.id, | ||
amount: Infinity, | ||
}); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
}, | ||
); | ||
|
||
test( | ||
"withdraw NaN", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.withdraw({ userId: user.id, amount: NaN }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
} | ||
) | ||
"withdraw NaN", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.withdraw({ userId: user.id, amount: NaN }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
}, | ||
); | ||
|
||
test( | ||
"deposit Infinity", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.deposit({ userId: user.id, amount: Infinity }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
} | ||
) | ||
"deposit Infinity", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.deposit({ userId: user.id, amount: Infinity }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
}, | ||
); | ||
|
||
test( | ||
"deposit NaN", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.deposit({ userId: user.id, amount: NaN }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
} | ||
) | ||
"deposit NaN", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.deposit({ userId: user.id, amount: NaN }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
}, | ||
); | ||
|
||
test( | ||
"deposit negative amount", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.deposit({ userId: user.id, amount: -100 }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
} | ||
"deposit negative amount", | ||
async (ctx: TestContext) => { | ||
const { user: user, token: token } = await ctx.modules.users.register({ | ||
username: faker.internet.userName(), | ||
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.deposit({ userId: user.id, amount: -100 }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
}, | ||
); | ||
|
||
test( | ||
|
@@ -131,11 +137,11 @@ test( | |
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.setBalance({ userId: user.id, balance: -1 }); | ||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.setBalance({ userId: user.id, balance: -1 }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
} | ||
}, | ||
); | ||
|
||
test( | ||
|
@@ -146,11 +152,11 @@ test( | |
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.setBalance({ userId: user.id, balance: NaN }); | ||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.setBalance({ userId: user.id, balance: NaN }); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
} | ||
}, | ||
); | ||
|
||
// Is this too restrictive of a test? | ||
|
@@ -162,9 +168,12 @@ test( | |
identity: { guest: {} }, | ||
}); | ||
|
||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.setBalance({ userId: user.id, balance: Infinity }); | ||
const error = await assertRejects(async () => { | ||
await ctx.modules.currency.setBalance({ | ||
userId: user.id, | ||
balance: Infinity, | ||
}); | ||
}, RuntimeError); | ||
assertEquals(error.code, "INVALID_AMOUNT"); | ||
} | ||
); | ||
}, | ||
); |
Oops, something went wrong.