-
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.
Merge pull request #80 from AppQuality/develop
release-2022-07-11-CP-2173
- Loading branch information
Showing
10 changed files
with
274 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Table from "./table"; | ||
|
||
type UploadedMediaParams = { | ||
id?: number; | ||
url?: string; | ||
creation_date?: string; | ||
}; | ||
const defaultItem: UploadedMediaParams = { | ||
id: 1, | ||
url: "www.exaple.com/media1.jpg", | ||
creation_date: "2020-01-01 00:00:00", | ||
}; | ||
class UploadedMedia extends Table<UploadedMediaParams> { | ||
protected name = "wp_appq_uploaded_media"; | ||
protected columns = [ | ||
"id INTEGER PRIMARY KEY", | ||
"url VARCHAR(255) NOT NULL", | ||
"creation_date DATETIME NOT NULL", | ||
]; | ||
constructor() { | ||
super(defaultItem); | ||
} | ||
} | ||
const uploadedMedia = new UploadedMedia(); | ||
export default uploadedMedia; | ||
export type { UploadedMediaParams }; |
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
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,77 @@ | ||
import { data as certificationData } from "@src/__mocks__/mockedDb/certificationList"; | ||
import { data as testerCertificationData } from "@src/__mocks__/mockedDb/testerCertification"; | ||
import { data as userMetaData } from "@src/__mocks__/mockedDb/wp_usermeta"; | ||
import app from "@src/app"; | ||
import request from "supertest"; | ||
|
||
describe("Route POST single-certification", () => { | ||
beforeEach(async () => { | ||
return new Promise(async (resolve) => { | ||
await certificationData.certification1(); | ||
await userMetaData.basicMeta(); | ||
|
||
resolve(null); | ||
}); | ||
}); | ||
afterEach(async () => { | ||
return new Promise(async (resolve) => { | ||
await testerCertificationData.drop(); | ||
await certificationData.drop(); | ||
await userMetaData.drop(); | ||
|
||
resolve(null); | ||
}); | ||
}); | ||
|
||
it("Should answer 403 if not logged in", async () => { | ||
const response = await request(app).delete("/users/me/certifications/1"); | ||
expect(response.status).toBe(403); | ||
}); | ||
it("Should return 201 and the resource if a certification is sent", async () => { | ||
const response = await request(app) | ||
.post("/users/me/certifications") | ||
.send({ certification_id: 1, achievement_date: "2020-01-01" }) | ||
.set("authorization", "Bearer tester"); | ||
expect(response.status).toBe(201); | ||
expect(response.body).toMatchObject({ | ||
id: 1, | ||
name: "Best Tryber Ever", | ||
area: "Testing 360", | ||
institute: "Tryber", | ||
achievement_date: "2020-01-01", | ||
}); | ||
}); | ||
//new user doesn't have any certification and doesn't have emptyCerts meta | ||
// when add first certification, it should add emptyCerts meta to usermeta as false | ||
// if user remove all certifications, remain emptyCerts meta as false | ||
it("Should return an error if sending an inexistent certification", async () => { | ||
const response = await request(app) | ||
.post("/users/me/certifications") | ||
.send({ certification_id: 69, achievement_date: "2020-01-01" }) | ||
.set("authorization", "Bearer tester"); | ||
|
||
expect(response.status).toBe(400); | ||
expect(response.body).toMatchObject({ | ||
id: 0, | ||
element: "certifications", | ||
message: "Can't find certification with id 69", | ||
}); | ||
}); | ||
it("Should return an error if send a certification that the user already owns", async () => { | ||
const response = await request(app) | ||
.post("/users/me/certifications") | ||
.send({ certification_id: 1, achievement_date: "2020-01-01" }) | ||
.set("authorization", "Bearer tester"); | ||
|
||
const responseTwinCertification = await request(app) | ||
.post("/users/me/certifications") | ||
.send({ certification_id: 1, achievement_date: "2020-01-01" }) | ||
.set("authorization", "Bearer tester"); | ||
|
||
expect(responseTwinCertification.status).toBe(400); | ||
expect(responseTwinCertification.body).toMatchObject({ | ||
message: | ||
"Failed. Duplication entry. Certification already assigned to the tester.", | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.