-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Setup + utils tests (w/ Jest) (#5)
* test: Jest setup * test: Username * chore: Test coverage * fix: MongoDB in GitHub Actions * fix: ENV config in GitHub Actions
- Loading branch information
Showing
6 changed files
with
3,035 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Test | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- develop | ||
- master | ||
|
||
jobs: | ||
test: | ||
|
||
name: Test | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14.x | ||
|
||
- name: Setup MongoDB | ||
uses: supercharge/[email protected] | ||
with: | ||
mongodb-version: 4.4 | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: Run Jest | ||
run: yarn test:coverage | ||
env: | ||
MONGO_URI: "mongodb://127.0.0.1:27017/jest" |
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,71 @@ | ||
import { isValid } from "../utils"; | ||
import { getConnection } from "../utils/mongo"; | ||
import { Connection } from "mongoose"; | ||
|
||
describe("UTILS - isValid", () => { | ||
let connection: Connection | null = null; | ||
|
||
beforeAll(async () => { | ||
connection = await getConnection(); | ||
}); | ||
|
||
it("valid username", async () => { | ||
const { valid, message } = await isValid("Jeff"); | ||
|
||
expect(valid).toStrictEqual(true); | ||
expect(message).toStrictEqual(undefined); | ||
}); | ||
|
||
it("cannot use a username of less than 3 characters", async () => { | ||
const { valid, message } = await isValid("a"); | ||
|
||
expect(valid).toStrictEqual(false); | ||
expect(message).toStrictEqual("Minimum length: 3 characters"); | ||
}); | ||
|
||
it("cannot use a username of more than 15 characters", async () => { | ||
const { valid, message } = await isValid("aaaaaaaaaaaaaaaaaaaa"); | ||
|
||
expect(valid).toStrictEqual(false); | ||
expect(message).toStrictEqual("Maximum length: 15 characters"); | ||
}); | ||
|
||
it("can only use alphanumeric characters", async () => { | ||
const { valid, message } = await isValid("CakeUwU"); | ||
|
||
expect(valid).toStrictEqual(true); | ||
expect(message).toStrictEqual(undefined); | ||
}); | ||
|
||
it("can only use alphanumeric characters", async () => { | ||
const { valid, message } = await isValid("C@keUwU"); | ||
|
||
expect(valid).toStrictEqual(false); | ||
expect(message).toStrictEqual("No spaces or special characters"); | ||
}); | ||
|
||
it("cannot use a space in their username", async () => { | ||
const { valid, message } = await isValid("aaaaa aaaaa"); | ||
|
||
expect(valid).toStrictEqual(false); | ||
expect(message).toStrictEqual("No spaces or special characters"); | ||
}); | ||
|
||
it("cannot use a space (URI encoded) in their username", async () => { | ||
const { valid, message } = await isValid("aaaaa%20aaaaa"); | ||
|
||
expect(valid).toStrictEqual(false); | ||
expect(message).toStrictEqual("No spaces or special characters"); | ||
}); | ||
|
||
it("cannot create a username which violates blacklist", async () => { | ||
const { valid, message } = await isValid("ChefCake"); | ||
|
||
expect(valid).toStrictEqual(false); | ||
expect(message).toStrictEqual("Username not allowed"); | ||
}); | ||
|
||
afterAll(async () => { | ||
await connection?.close(); | ||
}); | ||
}); |
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,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
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
Oops, something went wrong.