mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-10 17:04:49 +08:00
Add user creation flow test (#2971) bruception
This commit is contained in:
parent
ba25f7872c
commit
6c666f12ba
4 changed files with 59 additions and 21 deletions
|
@ -1,19 +1,56 @@
|
|||
import request from "supertest";
|
||||
import server from "../../../src/app";
|
||||
import app from "../../../src/app";
|
||||
|
||||
const mockApp = request(app);
|
||||
|
||||
describe("user controller test", () => {
|
||||
it("should be able to sign up", (done) => {
|
||||
const newUser = {
|
||||
name: "Test",
|
||||
email: "mockemail@email.com",
|
||||
uid: "userId",
|
||||
};
|
||||
request(server)
|
||||
.post("/users/signup")
|
||||
.send(newUser)
|
||||
.set({
|
||||
Accept: "application/json",
|
||||
})
|
||||
.expect(200, done);
|
||||
describe("user creation flow", () => {
|
||||
it("should be able to check name, sign up, and get user data", async () => {
|
||||
await mockApp
|
||||
.get("/users/checkName/NewUser")
|
||||
.set({
|
||||
Accept: "application/json",
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const newUser = {
|
||||
name: "NewUser",
|
||||
uid: "123456789",
|
||||
email: "newuser@mail.com",
|
||||
};
|
||||
|
||||
await mockApp
|
||||
.post("/users/signup")
|
||||
.send(newUser)
|
||||
.set({
|
||||
Accept: "application/json",
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const response = await mockApp
|
||||
.get("/users")
|
||||
.send({
|
||||
uid: "123456789",
|
||||
})
|
||||
.set({
|
||||
Accept: "application/json",
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const {
|
||||
body: { data: userData },
|
||||
} = response;
|
||||
|
||||
expect(userData.name).toBe(newUser.name);
|
||||
expect(userData.email).toBe(newUser.email);
|
||||
expect(userData.uid).toBe(newUser.uid);
|
||||
|
||||
await mockApp
|
||||
.get("/users/checkName/NewUser")
|
||||
.set({
|
||||
Accept: "application/json",
|
||||
})
|
||||
.expect(409);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,10 +6,11 @@ export default {
|
|||
setupFilesAfterEnv: ["<rootDir>/setup-tests.ts"],
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
branches: 36,
|
||||
functions: 18,
|
||||
lines: 39,
|
||||
statements: 35,
|
||||
// These percentages should never decrease
|
||||
statements: 37,
|
||||
branches: 38,
|
||||
functions: 19,
|
||||
lines: 40,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -99,7 +99,7 @@ export async function getUser(
|
|||
): Promise<MonkeyResponse> {
|
||||
const { uid } = req.ctx.decodedToken;
|
||||
|
||||
let userInfo;
|
||||
let userInfo: MonkeyTypes.User;
|
||||
try {
|
||||
userInfo = await UserDAL.getUser(uid, "get user");
|
||||
} catch (e) {
|
||||
|
|
|
@ -72,7 +72,7 @@ function authenticateRequest(authOptions = DEFAULT_OPTIONS): Handler {
|
|||
function authenticateWithBody(
|
||||
body: MonkeyTypes.Request["body"]
|
||||
): MonkeyTypes.DecodedToken {
|
||||
const { uid } = body;
|
||||
const { uid, email } = body;
|
||||
|
||||
if (!uid) {
|
||||
throw new MonkeyError(
|
||||
|
@ -84,7 +84,7 @@ function authenticateWithBody(
|
|||
return {
|
||||
type: "Bearer",
|
||||
uid,
|
||||
email: "",
|
||||
email: email ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue