-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
api-likes.spec.ts
53 lines (42 loc) · 1.41 KB
/
api-likes.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// check this file using TypeScript if available
// @ts-check
import { User, Like } from "../../../src/models";
const apiLikes = `${Cypress.env("apiUrl")}/likes`;
type TestLikesCtx = {
authenticatedUser?: User;
transactionId?: string;
};
describe("Likes API", function () {
let ctx: TestLikesCtx = {};
before(() => {
// Hacky workaround to have the e2e tests pass when cy.visit('http://localhost:3000') is called
cy.request("GET", "/");
});
beforeEach(function () {
cy.task("db:seed");
cy.database("filter", "users").then((users: User[]) => {
ctx.authenticatedUser = users[0];
return cy.loginByApi(ctx.authenticatedUser.username);
});
cy.database("find", "likes").then((like: Like) => {
ctx.transactionId = like.transactionId;
});
});
context("GET /likes/:transactionId", function () {
it("gets a list of likes for a transaction", function () {
cy.request("GET", `${apiLikes}/${ctx.transactionId}`).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.likes.length).to.eq(1);
});
});
});
context("POST /likes/:transactionId", function () {
it("creates a new like for a transaction", function () {
cy.request("POST", `${apiLikes}/${ctx.transactionId}`, {
transactionId: ctx.transactionId,
}).then((response) => {
expect(response.status).to.eq(200);
});
});
});
});