|
| 1 | +/// <reference types="Cypress" /> |
| 2 | + |
| 3 | +describe('Upstream endpoints', () => { |
| 4 | + let token; |
| 5 | + let upstreamId; |
| 6 | + |
| 7 | + before(() => { |
| 8 | + cy.getToken().then((tok) => { |
| 9 | + token = tok; |
| 10 | + }); |
| 11 | + }); |
| 12 | + |
| 13 | + it('Should be able to create new Upstream', function() { |
| 14 | + cy.task('backendApiPost', { |
| 15 | + token: token, |
| 16 | + path: '/api/upstreams', |
| 17 | + data: { |
| 18 | + nginx_template_id: 5, |
| 19 | + name: 'CypressGeneratedUpstreamA', |
| 20 | + // These servers must be reachable by the Cypress CI stack! |
| 21 | + servers: [ |
| 22 | + { |
| 23 | + |
| 24 | + server: 'fullstack:80', |
| 25 | + weight: 100 |
| 26 | + }, |
| 27 | + { |
| 28 | + server: 'fullstack:443', |
| 29 | + weight: 50 |
| 30 | + } |
| 31 | + ] |
| 32 | + } |
| 33 | + }).then((data) => { |
| 34 | + // Check the swagger schema: |
| 35 | + cy.validateSwaggerSchema('post', 201, '/upstreams', data); |
| 36 | + expect(data.result).to.have.property('id'); |
| 37 | + expect(data.result.id).to.be.greaterThan(0); |
| 38 | + upstreamId = data.result.id; |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + it('Should be able to get a Upstream', function() { |
| 43 | + cy.task('backendApiGet', { |
| 44 | + token: token, |
| 45 | + path: '/api/upstreams/' + upstreamId |
| 46 | + }).then((data) => { |
| 47 | + // Check the swagger schema: |
| 48 | + cy.validateSwaggerSchema('get', 200, '/upstreams/{upstreamID}', data); |
| 49 | + expect(data.result).to.have.property('id'); |
| 50 | + expect(data.result).to.have.property('name', 'CypressGeneratedUpstreamA'); |
| 51 | + expect(data.result.id).to.be.greaterThan(0); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it('Should be able to get all Upstreams', function() { |
| 56 | + cy.task('backendApiGet', { |
| 57 | + token: token, |
| 58 | + path: '/api/upstreams' |
| 59 | + }).then((data) => { |
| 60 | + cy.validateSwaggerSchema('get', 200, '/upstreams', data); |
| 61 | + expect(data).to.have.property('result'); |
| 62 | + expect(data.result).to.have.property('items'); |
| 63 | + expect(data.result.items.length).to.be.greaterThan(0); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | +}); |
0 commit comments