New Angular UI from 1806
[vid.git] / vid-webpack-master / cypress / support / jsonBuilders / mocks / vid.mock.ts
1 declare namespace Cypress {
2   interface Chainable {
3     initVidMock: typeof initVidMock;
4     preventErrorsOnLoading : typeof preventErrorsOnLoading;
5     initCategoryParameter : typeof initCategoryParameter;
6   }
7 }
8
9 function preventErrorsOnLoading() : void {
10   cy.on('uncaught:exception', (err, runnable) => {
11     return false
12   });
13 }
14
15 function initGetToMenuInfo(response? : JSON) : void {
16     cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/topMenuInfo.json').then((res) => {
17       cy.server()
18         .route({
19           method: 'GET',
20           status : 200,
21           url : Cypress.config('baseUrl') + "/get_topMenuInfo",
22           response : response ? response : res
23         });
24     });
25
26 }
27
28
29 function initCategoryParameter(response? : JSON) : void {
30     cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/categoryParametres.json').then((res) => {
31       cy.server()
32         .route({
33           method: 'GET',
34           status : 200,
35           url : Cypress.config('baseUrl') + "/category_parameter**",
36           response : response ? response : res
37         });
38     })
39 }
40
41 function initFlags(response? : JSON, delay?: number, status?: number) : void {
42   cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/flags.json').then((res) => {
43     cy.server()
44       .route({
45         method: 'GET',
46         delay : delay ? delay : 0,
47         status : status ? status : 200,
48         url : Cypress.config('baseUrl') + "/flags**",
49         response : response ? response : res
50       }).as('initFlags');
51   })
52 }
53
54 function initAuditInfoVID(response? : JSON, delay?: number, status?: number) : void {
55   cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/auditInfoVid.json').then((res) => {
56     cy.server()
57       .route({
58         method: 'GET',
59         delay : delay ? delay : 0,
60         status : status ? status : 200,
61         url : Cypress.config('baseUrl') + "/asyncInstantiation/auditStatus/**?source=VID",
62         response : response ? response : res
63       }).as('initAuditInfoVID');
64   })
65 }
66
67 function initAuditInfoMSO(response? : JSON, delay?: number, status?: number) : void {
68   cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/auditInfoMSO.json').then((res) => {
69     cy.server()
70       .route({
71         method: 'GET',
72         delay : delay ? delay : 0,
73         status : status ? status : 200,
74         url : Cypress.config('baseUrl') + "/asyncInstantiation/auditStatus/**?source=MSO",
75         response : response ? response : res
76       }).as('initAuditInfoMSO');
77   })
78 }
79
80 function initVidMock(): void {
81   initGetToMenuInfo();
82   initCategoryParameter();
83   initFlags();
84   initAuditInfoVID();
85   initAuditInfoMSO();
86 }
87
88
89 Cypress.Commands.add('initVidMock', initVidMock);
90 Cypress.Commands.add('preventErrorsOnLoading', preventErrorsOnLoading);
91 Cypress.Commands.add('initCategoryParameter', initCategoryParameter);