Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | declare namespace Cypress { |
| 2 | interface Chainable { |
| 3 | initVidMock: typeof initVidMock; |
| 4 | preventErrorsOnLoading : typeof preventErrorsOnLoading; |
| 5 | initCategoryParameter : typeof initCategoryParameter; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 6 | initAuditInfoMSO: typeof initAuditInfoMSO; |
| 7 | initAuditInfoMSOALaCarte: typeof initAuditInfoMSOALaCarte; |
| 8 | initAsyncInstantiation : typeof initAsyncInstantiation; |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame^] | 9 | mockLatestVersionForService : typeof mockLatestVersionForService; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 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 |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 41 | }).as('initCategoryParameters'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 42 | }) |
| 43 | } |
| 44 | |
| 45 | function 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 | |
| 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 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 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 | |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame^] | 110 | function 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 Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 127 | |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame^] | 128 | function initVidMock(...args :any): void { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 129 | initGetToMenuInfo(); |
| 130 | initCategoryParameter(); |
| 131 | initFlags(); |
| 132 | initAuditInfoVID(); |
| 133 | initAuditInfoMSO(); |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame^] | 134 | mockLatestVersionForService(args[0]); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | |
| 138 | Cypress.Commands.add('initVidMock', initVidMock); |
| 139 | Cypress.Commands.add('preventErrorsOnLoading', preventErrorsOnLoading); |
| 140 | Cypress.Commands.add('initCategoryParameter', initCategoryParameter); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 141 | Cypress.Commands.add('initAuditInfoMSO', initAuditInfoMSO); |
| 142 | Cypress.Commands.add('initAuditInfoMSOALaCarte', initAuditInfoMSOALaCarte); |
| 143 | Cypress.Commands.add('initAsyncInstantiation', initAsyncInstantiation); |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame^] | 144 | Cypress.Commands.add('mockLatestVersionForService', mockLatestVersionForService); |
| 145 | |