From 882674867cdbed727526206c4342ff02dcb8bbc8 Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Fri, 6 Jan 2023 15:07:37 +1000 Subject: [PATCH] Added upstreams tests for cypress --- test/cypress/integration/api/Settings.spec.js | 6 +- .../cypress/integration/api/Upstreams.spec.js | 67 +++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 test/cypress/integration/api/Upstreams.spec.js diff --git a/test/cypress/integration/api/Settings.spec.js b/test/cypress/integration/api/Settings.spec.js index e4bffb2..f04655e 100644 --- a/test/cypress/integration/api/Settings.spec.js +++ b/test/cypress/integration/api/Settings.spec.js @@ -12,7 +12,7 @@ describe('Settings endpoints', () => { }); }); - it('Should be able to create new settting', function() { + it('Should be able to create new setting', function() { cy.task('backendApiPost', { token: token, path: '/api/settings', @@ -31,7 +31,7 @@ describe('Settings endpoints', () => { }); }); - it('Should be able to get a settting', function() { + it('Should be able to get a setting', function() { cy.task('backendApiGet', { token: token, path: '/api/settings/' + settingName @@ -44,7 +44,7 @@ describe('Settings endpoints', () => { }); }); - it('Should be able to update a settting', function() { + it('Should be able to update a setting', function() { cy.task('backendApiPut', { token: token, path: '/api/settings/' + settingName, diff --git a/test/cypress/integration/api/Upstreams.spec.js b/test/cypress/integration/api/Upstreams.spec.js new file mode 100644 index 0000000..236d76e --- /dev/null +++ b/test/cypress/integration/api/Upstreams.spec.js @@ -0,0 +1,67 @@ +/// + +describe('Upstream endpoints', () => { + let token; + let upstreamId; + + before(() => { + cy.getToken().then((tok) => { + token = tok; + }); + }); + + it('Should be able to create new Upstream', function() { + cy.task('backendApiPost', { + token: token, + path: '/api/upstreams', + data: { + nginx_template_id: 5, + name: 'CypressGeneratedUpstreamA', + // These servers must be reachable by the Cypress CI stack! + servers: [ + { + + server: 'fullstack:80', + weight: 100 + }, + { + server: 'fullstack:443', + weight: 50 + } + ] + } + }).then((data) => { + // Check the swagger schema: + cy.validateSwaggerSchema('post', 201, '/upstreams', data); + expect(data.result).to.have.property('id'); + expect(data.result.id).to.be.greaterThan(0); + upstreamId = data.result.id; + }); + }); + + it('Should be able to get a Upstream', function() { + cy.task('backendApiGet', { + token: token, + path: '/api/upstreams/' + upstreamId + }).then((data) => { + // Check the swagger schema: + cy.validateSwaggerSchema('get', 200, '/upstreams/{upstreamID}', data); + expect(data.result).to.have.property('id'); + expect(data.result).to.have.property('name', 'CypressGeneratedUpstreamA'); + expect(data.result.id).to.be.greaterThan(0); + }); + }); + + it('Should be able to get all Upstreams', function() { + cy.task('backendApiGet', { + token: token, + path: '/api/upstreams' + }).then((data) => { + cy.validateSwaggerSchema('get', 200, '/upstreams', data); + expect(data).to.have.property('result'); + expect(data.result).to.have.property('items'); + expect(data.result.items.length).to.be.greaterThan(0); + }); + }); + +});