Merge "workflow parameters API"
[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     initAuditInfoMSO: typeof initAuditInfoMSO;
7     initAuditInfoMSOALaCarte: typeof initAuditInfoMSOALaCarte;
8     initAsyncInstantiation : typeof  initAsyncInstantiation;
9   }
10 }
11
12 function preventErrorsOnLoading() : void {
13   cy.on('uncaught:exception', (err, runnable) => {
14     return false
15   });
16 }
17
18 function initGetToMenuInfo(response? : JSON) : void {
19     cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/topMenuInfo.json').then((res) => {
20       cy.server()
21         .route({
22           method: 'GET',
23           status : 200,
24           url : Cypress.config('baseUrl') + "/get_topMenuInfo",
25           response : response ? response : res
26         });
27     });
28
29 }
30
31
32 function initCategoryParameter(response? : JSON) : void {
33     cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/categoryParametres.json').then((res) => {
34       cy.server()
35         .route({
36           method: 'GET',
37           status : 200,
38           url : Cypress.config('baseUrl') + "/category_parameter**",
39           response : response ? response : res
40         }).as('initCategoryParameters');
41     })
42 }
43
44 function initFlags(response? : JSON, delay?: number, status?: number) : void {
45   cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/flags.json').then((res) => {
46     cy.server()
47       .route({
48         method: 'GET',
49         delay : delay ? delay : 0,
50         status : status ? status : 200,
51         url : Cypress.config('baseUrl') + "/flags**",
52         response : response ? response : res
53       }).as('initFlags');
54   })
55 }
56
57 function initAuditInfoVID(response? : JSON, delay?: number, status?: number) : void {
58   cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/auditInfoVid.json').then((res) => {
59     cy.server()
60       .route({
61         method: 'GET',
62         delay : delay ? delay : 0,
63         status : status ? status : 200,
64         url : Cypress.config('baseUrl') + "/asyncInstantiation/auditStatus/**?source=VID",
65         response : response ? response : res
66       }).as('initAuditInfoVID');
67   })
68 }
69
70 function initAuditInfoMSO(response? : JSON, delay?: number, status?: number) : void {
71   cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/auditInfoMSO.json').then((res) => {
72     cy.server()
73       .route({
74         method: 'GET',
75         delay : delay ? delay : 0,
76         status : status ? status : 200,
77         url : Cypress.config('baseUrl') + "/asyncInstantiation/auditStatus/**?source=MSO",
78         response : response ? response : res
79       }).as('initAuditInfoMSO');
80   })
81 }
82
83 function initAuditInfoMSOALaCarte(response? : JSON, delay?: number, status?: number) : void {
84   cy.readFile('../vid-automation/src/test/resources/a-la-carte/auditInfoMSOALaCarte.json').then((res) => {
85     cy.server()
86       .route({
87         method: 'GET',
88         delay : delay ? delay : 0,
89         status : status ? status : 200,
90         url : Cypress.config('baseUrl') + "/asyncInstantiation/auditStatus/**/mso**",
91         response : response ? response : res
92       }).as('initAuditInfoMSOAlaCarte');
93   })
94 }
95
96 function initAsyncInstantiation(response? : JSON, delay?: number, status?: number) : void {
97   cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/basicAsyncInstantiation.json').then((res) => {
98     cy.server()
99       .route({
100         method: 'GET',
101         delay : delay ? delay : 0,
102         status : status ? status : 200,
103         url : Cypress.config('baseUrl') + "/asyncInstantiation",
104         response : response ? response : res
105       }).as('initAsyncInstantiation');
106   })
107 }
108
109
110
111 function initVidMock(): void {
112   initGetToMenuInfo();
113   initCategoryParameter();
114   initFlags();
115   initAuditInfoVID();
116   initAuditInfoMSO();
117 }
118
119
120 Cypress.Commands.add('initVidMock', initVidMock);
121 Cypress.Commands.add('preventErrorsOnLoading', preventErrorsOnLoading);
122 Cypress.Commands.add('initCategoryParameter', initCategoryParameter);
123 Cypress.Commands.add('initAuditInfoMSO', initAuditInfoMSO);
124 Cypress.Commands.add('initAuditInfoMSOALaCarte', initAuditInfoMSOALaCarte);
125 Cypress.Commands.add('initAsyncInstantiation', initAsyncInstantiation);