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

(-)a/t/cypress/integration/t/mockData.ts (+8 lines)
Lines 6-11 describe("Generate Random Patron", () => { Link Here
6
            expect(mockPatron).to.have.property("patron_id");
6
            expect(mockPatron).to.have.property("patron_id");
7
        });
7
        });
8
    });
8
    });
9
    it("should generate a random patron with predefined values", () => {
10
        cy.task("buildSampleObject", {
11
            object: "patron",
12
            values: { surname: "test_surname" },
13
        }).then(mockPatron => {
14
            expect(mockPatron.surname).to.equal("test_surname");
15
        });
16
    });
9
});
17
});
10
18
11
describe("Generate Random Patrons", () => {
19
describe("Generate Random Patrons", () => {
(-)a/t/cypress/plugins/mockData.js (-7 / +10 lines)
Lines 26-52 const generateMockData = type => { Link Here
26
    }
26
    }
27
};
27
};
28
28
29
const generateDataFromSchema = properties => {
29
const generateDataFromSchema = (properties, values = {}) => {
30
    const mockData = {};
30
    const mockData = {};
31
    Object.entries(properties).forEach(([key, value]) => {
31
    Object.entries(properties).forEach(([key, value]) => {
32
        mockData[key] = generateMockData(value.type);
32
        if (values.hasOwnProperty(key)) {
33
            mockData[key] = values[key];
34
        } else {
35
            mockData[key] = generateMockData(value.type);
36
        }
33
    });
37
    });
34
    return mockData;
38
    return mockData;
35
};
39
};
36
40
37
const buildSampleObjects = ({ object, count = 1 }) => {
41
const buildSampleObjects = ({ object, values, count = 1 }) => {
38
    if (!objects.hasOwnProperty(object)) {
42
    if (!objects.hasOwnProperty(object)) {
39
        throw new Error(`Object type not supported: ${object}`);
43
        throw new Error(`Object type not supported: ${object}`);
40
    }
44
    }
41
    const yamlPath = `api/v1/swagger/definitions/${objects[object].spec}.yaml`;
45
    const yamlPath = `api/v1/swagger/definitions/${objects[object].spec}.yaml`;
42
    const schema = readYamlFile(yamlPath);
46
    const schema = readYamlFile(yamlPath);
43
    return Array.from({ length: count }, () =>
47
    return Array.from({ length: count }, () =>
44
        generateDataFromSchema(schema.properties)
48
        generateDataFromSchema(schema.properties, values)
45
    );
49
    );
46
};
50
};
47
51
48
const buildSampleObject = object => {
52
const buildSampleObject = ({ object, values = {} }) => {
49
    return buildSampleObjects({ object })[0];
53
    return buildSampleObjects({ object, values })[0];
50
};
54
};
51
55
52
module.exports = {
56
module.exports = {
53
- 

Return to bug 38503