This repository has been archived by the owner on Mar 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added improved validation and tests to backend models (#269)
- Loading branch information
Showing
17 changed files
with
337 additions
and
120 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
41 changes: 41 additions & 0 deletions
41
packages/backend-core/src/models/__tests__/public-user-test.ts
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,41 @@ | ||
/* | ||
* CS3099 Group A3 | ||
*/ | ||
|
||
import test from "ava"; | ||
import { validate } from "class-validator"; | ||
import { PublicUser, UserProfile } from "../public-user"; | ||
|
||
test("Invalid username", async (t) => { | ||
const user = new PublicUser(); | ||
user.profile = new UserProfile(); | ||
user.profile.name = "foo"; | ||
|
||
const result = await validate(user); | ||
|
||
t.is(result.length, 1); | ||
}); | ||
|
||
test("Invalid profile", async (t) => { | ||
const user = new PublicUser(); | ||
user.username = "foo"; | ||
|
||
const result = await validate(user); | ||
|
||
t.is(result.length, 1); | ||
}); | ||
|
||
test("toJSON", (t) => { | ||
const user = new PublicUser(); | ||
user.username = "foo"; | ||
|
||
user.profile = new UserProfile(); | ||
user.profile.name = "bar"; | ||
|
||
t.deepEqual(user.toJSON(), { | ||
username: "foo", | ||
profile: { | ||
name: "bar", | ||
}, | ||
}); | ||
}); |
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
Oops, something went wrong.