mirror of
https://github.com/usatiuk/writer.git
synced 2025-10-29 00:17:48 +01:00
login/signup users
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import { expect } from "chai";
|
||||
import { connect } from "config/database";
|
||||
import * as request from "supertest";
|
||||
import { getConnection } from "typeorm";
|
||||
import { app } from "~app";
|
||||
import { IUserAuthJSON, User } from "~entity/User";
|
||||
|
||||
import { ISeed, seedDB } from "./util";
|
||||
|
||||
const callback = app.callback();
|
||||
|
||||
let seed: ISeed;
|
||||
|
||||
describe("users", () => {
|
||||
@@ -18,13 +24,65 @@ describe("users", () => {
|
||||
seed = await seedDB();
|
||||
});
|
||||
|
||||
it("should get user", async () => {});
|
||||
it("should get user", async () => {
|
||||
const response = await request(callback)
|
||||
.get("/users/user")
|
||||
.set({ Authorization: `Bearer ${seed.user1.toJWT()}` })
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200);
|
||||
|
||||
it("should login user", async () => {});
|
||||
expect(response.body.errors).to.be.false;
|
||||
|
||||
it("should not login user with wrong password", async () => {});
|
||||
const { jwt: _, ...user } = response.body.data as IUserAuthJSON;
|
||||
|
||||
it("should signup user", async () => {});
|
||||
expect(user).to.deep.equal(seed.user1.toJSON());
|
||||
});
|
||||
|
||||
it("should not signup user with duplicate username", async () => {});
|
||||
it("should login user", async () => {
|
||||
const response = await request(callback)
|
||||
.get("/users/login")
|
||||
.send({ username: "User1", password: "User1" })
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.errors).to.be.false;
|
||||
|
||||
const { jwt: _, ...user } = response.body.data as IUserAuthJSON;
|
||||
|
||||
expect(user).to.deep.equal(seed.user1.toJSON());
|
||||
});
|
||||
|
||||
it("should not login user with wrong password", async () => {
|
||||
const response = await request(callback)
|
||||
.get("/users/login")
|
||||
.send({ username: "User1", password: "asdf" })
|
||||
.expect(404);
|
||||
|
||||
expect(response.body).to.deep.equal({});
|
||||
});
|
||||
|
||||
it("should signup user", async () => {
|
||||
const response = await request(callback)
|
||||
.get("/users/signup")
|
||||
.send({ username: "NUser1", password: "NUser1" })
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.errors).to.be.false;
|
||||
|
||||
const { jwt: _, ...user } = response.body.data as IUserAuthJSON;
|
||||
|
||||
const newUser = await User.findOneOrFail({ username: "NUser1" });
|
||||
|
||||
expect(user).to.deep.equal(newUser.toJSON());
|
||||
});
|
||||
|
||||
it("should not signup user with duplicate username", async () => {
|
||||
const response = await request(callback)
|
||||
.get("/users/signup")
|
||||
.send({ username: "User1", password: "NUser1" })
|
||||
.expect(400);
|
||||
|
||||
expect(response.body).to.deep.equal({});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user