-
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.
feat(Querries):Admin querry management
- Loading branch information
YvetteNyibuka
committed
Jul 25, 2024
1 parent
e2a9453
commit 5b8a815
Showing
49 changed files
with
1,290 additions
and
260 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import app from "../app"; | ||
import request from "supertest"; | ||
import database_models, { | ||
connectionToDatabase, | ||
} from "../database/config/db.config"; | ||
import { deleteTableData } from "../utils/database.utils"; | ||
import { NewUser } from "../mock/static"; | ||
import { v4 as uuidV4 } from "uuid"; | ||
import { Token } from "../database/models/token"; | ||
|
||
jest.setTimeout(30000); | ||
|
||
function logErrors( | ||
err: { stack: any }, | ||
_req: any, | ||
_res: any, | ||
next: (arg0: any) => void, | ||
) { | ||
console.log(err.stack); | ||
next(err); | ||
} | ||
|
||
const Jest_request = request(app.use(logErrors)); | ||
|
||
let token = ""; | ||
let querryId: string; | ||
|
||
describe("NOTIFICATIONS TEST", () => { | ||
beforeAll(async () => { | ||
await connectionToDatabase(); | ||
}); | ||
afterAll(async () => { | ||
await deleteTableData(database_models.User, "users"); | ||
await deleteTableData(database_models.Querries, "querries"); | ||
}); | ||
it("it should register a user and return 201", async () => { | ||
const { body } = await Jest_request.post("/api/v1/users/register") | ||
.send(NewUser) | ||
.expect(201); | ||
expect(body.status).toStrictEqual("SUCCESS"); | ||
expect(body.message).toStrictEqual( | ||
"Account Created successfully, Please Verify your Account", | ||
); | ||
|
||
const tokenRecord = await Token.findOne(); | ||
token = tokenRecord?.dataValues.token ?? ""; | ||
}); | ||
|
||
it("should successfully login a user and return 200", async () => { | ||
const loginUser = { | ||
email: NewUser.email, | ||
password: NewUser.password, | ||
}; | ||
|
||
await database_models.User.update( | ||
{ isVerified: true, role: "12afd4f1-0bed-4a3b-8ad5-0978dabf8fcd" }, | ||
{ where: { email: loginUser.email } }, | ||
); | ||
|
||
const { body } = await Jest_request.post("/api/v1/users/login") | ||
.send(loginUser) | ||
.expect(200); | ||
expect(body.status).toStrictEqual("SUCCESS"); | ||
expect(body.message).toStrictEqual("Login successfully!"); | ||
expect(body.data).toBeDefined(); | ||
token = body.data; | ||
}); | ||
|
||
// =================================QUERRIES TESTS================================ | ||
|
||
it("It should create querry when customer want to communicate to app owner", async () => { | ||
const newQuerry = { | ||
firstName: "Izanyibuka", | ||
lastName: "Yvette", | ||
subject: "Biiter", | ||
email: "[email protected]", | ||
message: "I hated this app", | ||
}; | ||
const { body } = await Jest_request.post("/api/v1/querries") | ||
.send(newQuerry) | ||
.expect(201); | ||
expect(body.status).toStrictEqual("CREATED"); | ||
querryId = body.data.id; | ||
}); | ||
|
||
it("It should return all querry", async () => { | ||
const { body } = await Jest_request.get("/api/v1/querries") | ||
.set("Authorization", `Bearer ${token}`) | ||
.expect(200); | ||
expect(body.status).toStrictEqual("SUCCESS"); | ||
}); | ||
it("It should return a single querry", async () => { | ||
const { body } = await Jest_request.get(`/api/v1/querries/${querryId}`) | ||
.set("Authorization", `Bearer ${token}`) | ||
.expect(200); | ||
expect(body.status).toStrictEqual("SUCCESS"); | ||
}); | ||
|
||
it("it shouldreturn 404 if querry not found", async () => { | ||
const { body } = await Jest_request.get(`/api/v1/querries/${uuidV4()}`) | ||
.set("Authorization", `Bearer ${token}`) | ||
.expect(404); | ||
expect(body.status).toStrictEqual("NOT FOUND"); | ||
}); | ||
}); |
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.