Sorting functionality on audit info screen
[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     mockLatestVersionForService : typeof  mockLatestVersionForService;
10     initAuditInfoMSOALaCarteNew: typeof initAuditInfoMSOALaCarteNew;
11   }
12 }
13
14 function preventErrorsOnLoading() : void {
15   cy.on('uncaught:exception', (err, runnable) => {
16     return false
17   });
18 }
19
20 function initGetToMenuInfo(response? : JSON) : void {
21     cy.readFile('cypress/support/jsonBuilders/mocks/jsons/topMenuInfo.json').then((res) => {
22       cy.server()
23         .route({
24           method: 'GET',
25           status : 200,
26           url : Cypress.config('baseUrl') + "/get_topMenuInfo",
27           response : response ? response : res
28         });
29     });
30
31 }
32
33
34 function initCategoryParameter(response? : JSON) : void {
35     cy.readFile('cypress/support/jsonBuilders/mocks/jsons/categoryParametres.json').then((res) => {
36       cy.server()
37         .route({
38           method: 'GET',
39           status : 200,
40           url : Cypress.config('baseUrl') + "/category_parameter**",
41           response : response ? response : res
42         }).as('initCategoryParameters');
43     })
44 }
45
46 function initFlags(response? : JSON, delay?: number, status?: number) : void {
47   cy.readFile('cypress/support/jsonBuilders/mocks/jsons/flags.cypress.json').then((res) => {
48     cy.server()
49       .route({
50         method: 'GET',
51         delay : delay ? delay : 0,
52         status : status ? status : 200,
53         url : Cypress.config('baseUrl') + "/flags**",
54         response : response ? response : res
55       }).as('initFlags');
56   })
57 }
58
59 function initAuditInfoVID(response? : JSON, delay?: number, status?: number) : void {
60   cy.readFile('cypress/support/jsonBuilders/mocks/jsons/auditInfoVid.json').then((res) => {
61     cy.server()
62       .route({
63         method: 'GET',
64         delay : delay ? delay : 0,
65         status : status ? status : 200,
66         url : Cypress.config('baseUrl') + "/asyncInstantiation/auditStatus/**?source=VID",
67         response : response ? response : res
68       }).as('initAuditInfoVID');
69   })
70 }
71
72 function initAuditInfoMSO(response? : JSON, delay?: number, status?: number) : void {
73   cy.readFile('cypress/support/jsonBuilders/mocks/jsons/auditInfoMSO.json').then((res) => {
74     cy.server()
75       .route({
76         method: 'GET',
77         delay : delay ? delay : 0,
78         status : status ? status : 200,
79         url : Cypress.config('baseUrl') + "/asyncInstantiation/auditStatus/**?source=MSO",
80         response : response ? response : res
81       }).as('initAuditInfoMSO');
82   })
83 }
84
85 function initAuditInfoMSOALaCarte(response? : JSON, delay?: number, status?: number) : void {
86   cy.readFile('../vid-automation/src/test/resources/a-la-carte/auditInfoMSOALaCarte.json').then((res) => {
87     cy.server()
88       .route({
89         method: 'GET',
90         delay : delay ? delay : 0,
91         status : status ? status : 200,
92         url : Cypress.config('baseUrl') + "/asyncInstantiation/auditStatus/**/mso**",
93         response : response ? response : res
94       }).as('initAuditInfoMSOAlaCarte');
95   })
96 }
97
98 function initAuditInfoMSOALaCarteNew(response? : JSON, delay?: number, status?: number) : void {
99   cy.readFile('../vid-automation/src/test/resources/a-la-carte/auditInfoMSOALaCarteNew.json').then((res) => {
100     cy.server()
101       .route({
102         method: 'GET',
103         delay : delay ? delay : 0,
104         status : status ? status : 200,
105         url : Cypress.config('baseUrl') + "/asyncInstantiation/auditStatus/**/mso**",
106         response : response ? response : res
107       }).as('initAuditInfoMSOALaCarteNew');
108   })
109 }
110
111 function initAsyncInstantiation(response? : JSON, delay?: number, status?: number) : void {
112   cy.readFile('cypress/support/jsonBuilders/mocks/jsons/basicAsyncInstantiation.json').then((res) => {
113     cy.server()
114       .route({
115         method: 'GET',
116         delay : delay ? delay : 0,
117         status : status ? status : 200,
118         url : Cypress.config('baseUrl') + "/asyncInstantiation",
119         response : response ? response : res
120       }).as('initAsyncInstantiation');
121   })
122 }
123
124 function mockLatestVersionForService(serviceUuid: string, invariantId: string) {
125     cy.server().route({
126       url: Cypress.config('baseUrl') + '/aai_get_newest_model_version_by_invariant/' + invariantId,
127       method: 'GET',
128       status: 200,
129       response: {
130         "modelVersionId": serviceUuid,
131         "modelName": "SERVICE_INSTANCE_NAME",
132         "modelVersion": "2.0",
133         "distributionStatus": "DISTRIBUTION_COMPLETE_OK",
134         "resourceVersion": "resourceVersion",
135         "modelDescription": "modelDescription"
136       },
137     }).as("expectLatestServiceModelUpgradeVersion")
138 }
139
140 function initVidMock(): void {
141   initGetToMenuInfo();
142   initCategoryParameter();
143   initFlags();
144   initAuditInfoVID();
145   initAuditInfoMSO();
146 }
147
148
149 Cypress.Commands.add('initVidMock', initVidMock);
150 Cypress.Commands.add('preventErrorsOnLoading', preventErrorsOnLoading);
151 Cypress.Commands.add('initCategoryParameter', initCategoryParameter);
152 Cypress.Commands.add('initAuditInfoMSO', initAuditInfoMSO);
153 Cypress.Commands.add('initAuditInfoMSOALaCarte', initAuditInfoMSOALaCarte);
154 Cypress.Commands.add('initAuditInfoMSOALaCarteNew', initAuditInfoMSOALaCarteNew);
155 Cypress.Commands.add('initAsyncInstantiation', initAsyncInstantiation);
156 Cypress.Commands.add('mockLatestVersionForService', mockLatestVersionForService);
157