blob: 9698f47bbe9d38d8f72cf6b3e8fb7137c527aa7c [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001declare namespace Cypress {
2 interface Chainable {
3 initVidMock: typeof initVidMock;
4 preventErrorsOnLoading : typeof preventErrorsOnLoading;
5 initCategoryParameter : typeof initCategoryParameter;
Ittay Stern6f900cc2018-08-29 17:01:32 +03006 initAuditInfoMSO: typeof initAuditInfoMSO;
7 initAuditInfoMSOALaCarte: typeof initAuditInfoMSOALaCarte;
8 initAsyncInstantiation : typeof initAsyncInstantiation;
Einat Vinouzee1f79742019-08-27 16:01:01 +03009 mockLatestVersionForService : typeof mockLatestVersionForService;
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030010 }
11}
12
13function preventErrorsOnLoading() : void {
14 cy.on('uncaught:exception', (err, runnable) => {
15 return false
16 });
17}
18
19function 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
33function 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
Ittay Stern6f900cc2018-08-29 17:01:32 +030041 }).as('initCategoryParameters');
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030042 })
43}
44
45function initFlags(response? : JSON, delay?: number, status?: number) : void {
46 cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/flags.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
58function 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
71function 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
Ittay Stern6f900cc2018-08-29 17:01:32 +030084function 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
97function 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
Einat Vinouzee1f79742019-08-27 16:01:01 +0300110function mockLatestVersionForService(uuidObject :any) {
111 if(uuidObject && uuidObject.serviceUuid && uuidObject.invariantId){
112 cy.server().route({
113 url: Cypress.config('baseUrl') + '/aai_get_newest_model_version_by_invariant/' + uuidObject.invariantId,
114 method: 'GET',
115 status: 200,
116 response: {
117 "modelVersionId": uuidObject.serviceUuid,
118 "modelName": "SERVICE_INSTANCE_NAME",
119 "modelVersion": "2.0",
120 "distributionStatus": "DISTRIBUTION_COMPLETE_OK",
121 "resourceVersion": "resourceVersion",
122 "modelDescription": "modelDescription"
123 },
124 }).as("expectLatestServiceModelUpgradeVersion")
125 }
126}
Ittay Stern6f900cc2018-08-29 17:01:32 +0300127
Einat Vinouzee1f79742019-08-27 16:01:01 +0300128function initVidMock(...args :any): void {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +0300129 initGetToMenuInfo();
130 initCategoryParameter();
131 initFlags();
132 initAuditInfoVID();
133 initAuditInfoMSO();
Einat Vinouzee1f79742019-08-27 16:01:01 +0300134 mockLatestVersionForService(args[0]);
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +0300135}
136
137
138Cypress.Commands.add('initVidMock', initVidMock);
139Cypress.Commands.add('preventErrorsOnLoading', preventErrorsOnLoading);
140Cypress.Commands.add('initCategoryParameter', initCategoryParameter);
Ittay Stern6f900cc2018-08-29 17:01:32 +0300141Cypress.Commands.add('initAuditInfoMSO', initAuditInfoMSO);
142Cypress.Commands.add('initAuditInfoMSOALaCarte', initAuditInfoMSOALaCarte);
143Cypress.Commands.add('initAsyncInstantiation', initAsyncInstantiation);
Einat Vinouzee1f79742019-08-27 16:01:01 +0300144Cypress.Commands.add('mockLatestVersionForService', mockLatestVersionForService);
145