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

(-)a/t/cypress/integration/t/mockData.ts (-12 / +18 lines)
Lines 2-8 import { mount } from "@cypress/vue"; Link Here
2
2
3
describe("Generate Random Patron", () => {
3
describe("Generate Random Patron", () => {
4
    it("should generate a random patron from the schema", () => {
4
    it("should generate a random patron from the schema", () => {
5
        cy.task("buildSamplePatron").then(mockPatron => {
5
        cy.task("buildSampleObject", { object: "patron" }).then(mockPatron => {
6
            expect(mockPatron).to.have.property("patron_id");
6
            expect(mockPatron).to.have.property("patron_id");
7
        });
7
        });
8
    });
8
    });
Lines 10-35 describe("Generate Random Patron", () => { Link Here
10
10
11
describe("Generate Random Patrons", () => {
11
describe("Generate Random Patrons", () => {
12
    it("should generate 42 random patron from the schema", () => {
12
    it("should generate 42 random patron from the schema", () => {
13
        cy.task("buildSamplePatrons", 42).then(mockPatrons => {
13
        cy.task("buildSampleObjects", { object: "patron", count: 42 }).then(
14
            expect(mockPatrons.length).to.equal(42);
14
            mockPatrons => {
15
            expect(mockPatrons[0]).to.have.property("patron_id");
15
                expect(mockPatrons.length).to.equal(42);
16
        });
16
                expect(mockPatrons[0]).to.have.property("patron_id");
17
            }
18
        );
17
    });
19
    });
18
});
20
});
19
21
20
describe("Generate Random Library", () => {
22
describe("Generate Random Library", () => {
21
    it("should generate a random library from the schema", () => {
23
    it("should generate a random library from the schema", () => {
22
        cy.task("buildSampleLibrary").then(mockLibrary => {
24
        cy.task("buildSampleObject", { object: "library" }).then(
23
            expect(mockLibrary).to.have.property("library_id");
25
            mockLibrary => {
24
        });
26
                expect(mockLibrary).to.have.property("library_id");
27
            }
28
        );
25
    });
29
    });
26
});
30
});
27
31
28
describe("Generate Random Libraries", () => {
32
describe("Generate Random Libraries", () => {
29
    it("should generate 42 random library from the schema", () => {
33
    it("should generate 42 random library from the schema", () => {
30
        cy.task("buildSampleLibraries", 42).then(mockLibraries => {
34
        cy.task("buildSampleObjects", { object: "library", count: 42 }).then(
31
            expect(mockLibraries.length).to.equal(42);
35
            mockLibraries => {
32
            expect(mockLibraries[0]).to.have.property("library_id");
36
                expect(mockLibraries.length).to.equal(42);
33
        });
37
                expect(mockLibraries[0]).to.have.property("library_id");
38
            }
39
        );
34
    });
40
    });
35
});
41
});
(-)a/t/cypress/plugins/index.js (-10 / +3 lines)
Lines 18-36 module.exports = (on, config) => { Link Here
18
    mysql.configurePlugin(on);
18
    mysql.configurePlugin(on);
19
};
19
};
20
20
21
const {
21
const { buildSampleObject, buildSampleObjects } = require("./mockData.js");
22
    buildSamplePatron,
23
    buildSamplePatrons,
24
    buildSampleLibrary,
25
    buildSampleLibraries,
26
} = require("./mockData.js");
27
22
28
module.exports = (on, config) => {
23
module.exports = (on, config) => {
29
    on("task", {
24
    on("task", {
30
        buildSamplePatron,
25
        buildSampleObject,
31
        buildSamplePatrons,
26
        buildSampleObjects,
32
        buildSampleLibrary,
33
        buildSampleLibraries,
34
    });
27
    });
35
    return config;
28
    return config;
36
};
29
};
(-)a/t/cypress/plugins/mockData.js (-21 / +17 lines)
Lines 1-6 Link Here
1
const { faker } = require("@faker-js/faker");
1
const { faker } = require("@faker-js/faker");
2
const { readYamlFile } = require("./../plugins/readYamlFile.js");
2
const { readYamlFile } = require("./../plugins/readYamlFile.js");
3
3
4
const objects = {
5
    patron: {
6
        spec: "patron",
7
    },
8
    library: {
9
        spec: "library",
10
    },
11
};
4
const generateMockData = type => {
12
const generateMockData = type => {
5
    switch (type) {
13
    switch (type) {
6
        case "string":
14
        case "string":
Lines 26-60 const generateDataFromSchema = properties => { Link Here
26
    return mockData;
34
    return mockData;
27
};
35
};
28
36
29
const buildSamplePatrons = (count = 1) => {
37
const buildSampleObjects = ({ object, count = 1 }) => {
30
    const yamlPath = "api/v1/swagger/definitions/patron.yaml";
38
    if (!objects.hasOwnProperty(object)) {
31
    const schema = readYamlFile(yamlPath);
39
        throw new Error(`Object type not supported: ${object}`);
32
    return Array.from({ length: count }, () =>
40
    }
33
        generateDataFromSchema(schema.properties)
41
    const yamlPath = `api/v1/swagger/definitions/${objects[object].spec}.yaml`;
34
    );
35
};
36
37
const buildSamplePatron = () => {
38
    return buildSamplePatrons()[0];
39
};
40
41
const buildSampleLibraries = (count = 1) => {
42
    const yamlPath = "api/v1/swagger/definitions/library.yaml";
43
    const schema = readYamlFile(yamlPath);
42
    const schema = readYamlFile(yamlPath);
44
    return Array.from({ length: count }, () =>
43
    return Array.from({ length: count }, () =>
45
        generateDataFromSchema(schema.properties)
44
        generateDataFromSchema(schema.properties)
46
    );
45
    );
47
};
46
};
48
47
49
const buildSampleLibrary = () => {
48
const buildSampleObject = object => {
50
    return buildSampleLibraries()[0];
49
    return buildSampleObjects({ object })[0];
51
};
50
};
52
51
53
module.exports = {
52
module.exports = {
54
    generateMockData,
53
    generateMockData,
55
    generateDataFromSchema,
54
    generateDataFromSchema,
56
    buildSamplePatron,
55
    buildSampleObject,
57
    buildSamplePatrons,
56
    buildSampleObjects,
58
    buildSampleLibrary,
59
    buildSampleLibraries,
60
};
57
};
61
- 

Return to bug 38503