generated from Kan-A-Pesh/express-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a78b40
commit f538caf
Showing
7 changed files
with
83 additions
and
25 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import createApp from "@/app"; | ||
import AuthController from "@/controllers/auth"; | ||
import { get, post, put } from "../utils"; | ||
import { readFileSync } from "fs"; | ||
import path from "path"; | ||
|
||
const app = createApp("e2e-users"); | ||
|
||
const testGlobals = { | ||
userAvatarUrl: null | ||
}; | ||
|
||
describe("Test users", () => { | ||
const email = "[email protected]"; | ||
const token = AuthController.generateCreationToken(email); | ||
|
@@ -112,11 +118,13 @@ describe("Test users", () => { | |
const authToken = AuthController.generateAuthToken(email); | ||
|
||
test("should edit the user", async () => { | ||
const avatar = readFileSync(path.join(__dirname, "..", "assets", "avatar.png"), "base64"); | ||
|
||
const res = await put( | ||
app, | ||
"/users/:uuid", | ||
{ uuid: userUuid }, | ||
{ quote: "test" }, | ||
{ quote: "test", avatar: avatar }, | ||
{ Authorization: `Bearer ${authToken}` } | ||
); | ||
|
||
|
@@ -131,13 +139,33 @@ describe("Test users", () => { | |
uuid: userUuid, | ||
email: email, | ||
username: "test-users", | ||
avatarUrl: null, | ||
avatarUrl: expect.stringMatching( | ||
/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/ | ||
), // UUID v4 regex | ||
clubId: null, | ||
quote: "test" | ||
} | ||
} | ||
] | ||
}); | ||
|
||
testGlobals.userAvatarUrl = res.body.response[0].data.avatarUrl; | ||
}); | ||
|
||
test("should get the user avatar", async () => { | ||
const res = await get(app, "/blob/:uuid", { uuid: testGlobals.userAvatarUrl ?? "invalid" }); | ||
|
||
expect(res.body).toStrictEqual({ | ||
masterStatus: 200, | ||
sentAt: expect.any(Number), | ||
response: [ | ||
{ | ||
status: 200, | ||
success: true, | ||
data: expect.any(String) | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
test("should get 'invalid token' error", async () => { | ||
|
@@ -179,7 +207,7 @@ describe("Test users", () => { | |
uuid: userUuid, | ||
email: email, | ||
username: "test-users", | ||
avatarUrl: null, | ||
avatarUrl: testGlobals.userAvatarUrl, | ||
clubId: null, | ||
quote: "test" | ||
} | ||
|
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,23 @@ | ||
import createApp from "@/app"; | ||
import { get } from "../utils"; | ||
|
||
const app = createApp("unit-blob"); | ||
|
||
describe("Test status page", () => { | ||
test("should get a 'image not found' error", async () => { | ||
const res = await get(app, "/blob/:uuid", { uuid: "definitely-not-a-valid-uuid" }); | ||
|
||
expect(res.body).toStrictEqual({ | ||
masterStatus: 404, | ||
sentAt: expect.any(Number), | ||
response: [ | ||
{ | ||
status: 404, | ||
success: false, | ||
error: "errors.image.notFound", | ||
translatedError: "Image not found" | ||
} | ||
] | ||
}); | ||
}); | ||
}); |