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

(-)a/cypress.config.ts (+4 lines)
Lines 16-19 export default defineConfig({ Link Here
16
        specPattern: "t/cypress/integration/**/*.*",
16
        specPattern: "t/cypress/integration/**/*.*",
17
        supportFile: "t/cypress/support/e2e.js",
17
        supportFile: "t/cypress/support/e2e.js",
18
    },
18
    },
19
    env: {
20
        apiUsername: "koha",
21
        apiPassword: "koha",
22
    },
19
});
23
});
(-)a/t/cypress/plugins/auth.js (+12 lines)
Line 0 Link Here
1
const { Buffer } = require("buffer");
2
3
const getBasicAuthHeader = (username, password) => {
4
    const credentials = Buffer.from(`${username}:${password}`).toString(
5
        "base64"
6
    );
7
    return `Basic ${credentials}`;
8
};
9
10
module.exports = {
11
    getBasicAuthHeader,
12
};
(-)a/t/cypress/plugins/index.js (-1 / +14 lines)
Lines 8-19 const { Link Here
8
    deleteSampleObjects,
8
    deleteSampleObjects,
9
} = require("./insertData.js");
9
} = require("./insertData.js");
10
10
11
const { getBasicAuthHeader } = require("./auth.js");
12
11
const { query } = require("./db.js");
13
const { query } = require("./db.js");
12
14
13
const { apiGet, apiPost, apiPut, apiDelete } = require("./api-client.js");
15
const { apiGet, apiPost, apiPut, apiDelete } = require("./api-client.js");
14
16
15
module.exports = (on, config) => {
17
module.exports = (on, config) => {
16
    const baseUrl = config.baseUrl;
18
    const baseUrl = config.baseUrl;
19
    const authHeader = getBasicAuthHeader(
20
        config.env.apiUsername,
21
        config.env.apiPassword
22
    );
23
17
    on("dev-server:start", options =>
24
    on("dev-server:start", options =>
18
        startDevServer({
25
        startDevServer({
19
            options,
26
            options,
Lines 21-30 module.exports = (on, config) => { Link Here
21
    );
28
    );
22
29
23
    on("task", {
30
    on("task", {
31
        getBasicAuthHeader() {
32
            return getBasicAuthHeader(
33
                config.env.apiUsername,
34
                config.env.apiPassword
35
            );
36
        },
24
        buildSampleObject,
37
        buildSampleObject,
25
        buildSampleObjects,
38
        buildSampleObjects,
26
        insertSampleBiblio({ item_count }) {
39
        insertSampleBiblio({ item_count }) {
27
            return insertSampleBiblio(item_count, baseUrl);
40
            return insertSampleBiblio(item_count, baseUrl, authHeader);
28
        },
41
        },
29
        insertObject({ type, object }) {
42
        insertObject({ type, object }) {
30
            return insertObject(type, object, baseUrl, authHeader);
43
            return insertObject(type, object, baseUrl, authHeader);
(-)a/t/cypress/plugins/insertData.js (-6 / +3 lines)
Lines 2-10 const { buildSampleObject, buildSampleObjects } = require("./mockData.js"); Link Here
2
const { query } = require("./db.js");
2
const { query } = require("./db.js");
3
3
4
const { APIClient } = require("./dist/api-client.cjs.js");
4
const { APIClient } = require("./dist/api-client.cjs.js");
5
const { Buffer } = require("buffer");
6
5
7
const insertSampleBiblio = async (item_count, baseUrl) => {
6
const insertSampleBiblio = async (item_count, baseUrl, authHeader) => {
8
    let client = APIClient.default;
7
    let client = APIClient.default;
9
    let generated_objects = {};
8
    let generated_objects = {};
10
    const objects = [{ object: "library" }, { object: "item_type" }];
9
    const objects = [{ object: "library" }, { object: "item_type" }];
Lines 53-65 const insertSampleBiblio = async (item_count, baseUrl) => { Link Here
53
            },
52
            },
54
        ],
53
        ],
55
    };
54
    };
56
    const credentials = Buffer.from("koha:koha").toString("base64");
57
    let result = await client.koha.post({
55
    let result = await client.koha.post({
58
        endpoint: `${baseUrl}/api/v1/biblios`,
56
        endpoint: `${baseUrl}/api/v1/biblios`,
59
        headers: {
57
        headers: {
60
            "Content-Type": "application/marc-in-json",
58
            "Content-Type": "application/marc-in-json",
61
            "x-confirm-not-duplicate": 1,
59
            "x-confirm-not-duplicate": 1,
62
            Authorization: "Basic " + credentials,
60
            Authorization: authHeader,
63
        },
61
        },
64
        body: biblio,
62
        body: biblio,
65
    });
63
    });
Lines 132-138 const insertSampleBiblio = async (item_count, baseUrl) => { Link Here
132
                body: item,
130
                body: item,
133
                headers: {
131
                headers: {
134
                    "Content-Type": "application/json",
132
                    "Content-Type": "application/json",
135
                    Authorization: "Basic " + credentials,
133
                    Authorization: authHeader,
136
                },
134
                },
137
            })
135
            })
138
            .then(i => createdItems.push(i));
136
            .then(i => createdItems.push(i));
139
- 

Return to bug 40174