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