View | Details | Raw Unified | Return to bug 40173
Collapse All | Expand All

(-)a/t/cypress/integration/t/api-client.ts (+28 lines)
Line 0 Link Here
1
const { APIClient } = require("./../../plugins/dist/api-client.cjs.js");
2
3
describe("Using APIClient", () => {
4
    let client = APIClient.default;
5
    it("should 404 for non-existent biblio", async () => {
6
        try {
7
            await client.koha.get({
8
                endpoint: "/api/v1/public/biblios/99999",
9
                return_response: true,
10
            });
11
        } catch (error) {
12
            expect(error.response.status).to.equal(404);
13
        }
14
    });
15
});
16
17
describe("Using the api-client plugin", () => {
18
    it("should 404 for non-existent biblio", async () => {
19
        try {
20
            await cy.task("apiGet", {
21
                endpoint: "/api/v1/public/biblios/99999",
22
                return_response: true,
23
            });
24
        } catch (error) {
25
            expect(error.response.status).to.equal(404);
26
        }
27
    });
28
});
(-)a/t/cypress/plugins/api-client.js (+56 lines)
Line 0 Link Here
1
const { APIClient } = require("./dist/api-client.cjs.js");
2
3
const client = APIClient.default.koha;
4
5
const prepareRequest = params => {
6
    const { baseUrl, endpoint, authHeader, headers = {}, ...rest } = params;
7
    const url = baseUrl + endpoint;
8
    const finalHeaders = {
9
        ...headers,
10
        ...(authHeader ? { Authorization: authHeader } : {}),
11
    };
12
    return { url, headers: finalHeaders, rest };
13
};
14
15
const apiGet = params => {
16
    const { url, headers, rest } = prepareRequest(params);
17
    return client.get({
18
        endpoint: url,
19
        headers,
20
        ...rest,
21
    });
22
};
23
24
const apiPost = params => {
25
    const { url, headers, rest } = prepareRequest(params);
26
    return client.post({
27
        endpoint: url,
28
        headers,
29
        ...rest,
30
    });
31
};
32
33
const apiPut = params => {
34
    const { url, headers, rest } = prepareRequest(params);
35
    return client.put({
36
        endpoint: url,
37
        headers,
38
        ...rest,
39
    });
40
};
41
42
const apiDelete = params => {
43
    const { url, headers, rest } = prepareRequest(params);
44
    return client.delete({
45
        endpoint: url,
46
        headers,
47
        ...rest,
48
    });
49
};
50
51
module.exports = {
52
    apiGet,
53
    apiPost,
54
    apiPut,
55
    apiDelete,
56
};
(-)a/t/cypress/plugins/index.js (-1 / +15 lines)
Lines 4-9 const mysql = require("cypress-mysql"); Link Here
4
4
5
const { buildSampleObject, buildSampleObjects } = require("./mockData.js");
5
const { buildSampleObject, buildSampleObjects } = require("./mockData.js");
6
6
7
const { apiGet, apiPost, apiPut, apiDelete } = require("./api-client.js");
8
7
module.exports = (on, config) => {
9
module.exports = (on, config) => {
8
    on("dev-server:start", options =>
10
    on("dev-server:start", options =>
9
        startDevServer({
11
        startDevServer({
Lines 16-21 module.exports = (on, config) => { Link Here
16
    on("task", {
18
    on("task", {
17
        buildSampleObject,
19
        buildSampleObject,
18
        buildSampleObjects,
20
        buildSampleObjects,
21
22
        apiGet(args) {
23
            return apiGet({ ...args, baseUrl, authHeader });
24
        },
25
        apiPost(args) {
26
            return apiPost({ ...args, baseUrl, authHeader });
27
        },
28
        apiPut(args) {
29
            return apiPut({ ...args, baseUrl, authHeader });
30
        },
31
        apiDelete(args) {
32
            return apiDelete({ ...args, baseUrl, authHeader });
33
        },
19
    });
34
    });
20
    return config;
35
    return config;
21
};
36
};
22
- 

Return to bug 40173