test(ui): add simple Organization deleter for Cypress #before test reset
Closes:
MODIFY
manager/ui/war/ci/run-e2e.sh
manager/ui/war/ci/run-e2e.sh
@@ -27,7 +27,7 @@ yarn run wait-on -v -d 15000 -t 300000 -c waitOnConfig.js "http://$HOSTNAME:8877
# If CI env var set, use record mode and export to Cypress dashboard.
if [[ -n $CI ]]
then
- yarn cy:run --record --config baseUrl="http://$HOSTNAME:8877/apimanui/,retries=3,defaultCommandTimeout=10000"
+ yarn cy:run --record --config baseUrl="http://$HOSTNAME:8877/,retries=3,defaultCommandTimeout=10000"
else
- yarn cy:run --config baseUrl="http://$HOSTNAME:8877/apimanui/,retries=3,defaultCommandTimeout=10000"
+ yarn cy:run --config baseUrl="http://$HOSTNAME:8877/,retries=3,defaultCommandTimeout=10000"
fi
\ No newline at end of file

MODIFY
manager/ui/war/cypress/integration/Basic_Functionality.js
manager/ui/war/cypress/integration/Basic_Functionality.js
describe('Apiman e2e UI smoke test', () => {
before(() => {
+ cy.deleteOrg('TestOrganization');
cy.clearCookies();
- cy.visit('/');
+ cy.visit('/apimanui');
cy.typeLogin('admin', 'admin123!')
});
beforeEach(() => {
Cypress.Cookies.preserveOnce('JSESSIONID', 'OAuth_Token_Request_State');
- cy.visit('/');
+ cy.visit('/apimanui');
});
it('Create the Organization via NavBar and edit the description', () => {

MODIFY
manager/ui/war/cypress/support/commands.js
manager/ui/war/cypress/support/commands.js
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
-
Cypress.Commands.add('typeLogin', (user, pw) => {
cy.get('#username').type(user);
cy.get('#password').type(pw);
cy.get('#kc-login').click();
-})
+});
Cypress.Commands.add('visitTestOrganization', () => {
cy.get('#apiman-sidebar-orgs').trigger('mouseover');
cy.get('#apiman-sidebar-orgs-my-orgs').click();
cy.contains('TestOrganization').click();
-})
+});
Cypress.Commands.add('visitTestPlan', () => {
cy.visitTestOrganization();
cy.get('#tab-plans').click();
cy.contains('TestPlan').click();
-})
+});
Cypress.Commands.add('visitTestApi', () => {
cy.visitTestOrganization();
cy.get('#tab-apis').click();
cy.contains('TestApi').click();
-})
+});
Cypress.Commands.add('visitTestClient', () => {
cy.visitTestOrganization();
cy.get('#tab-clients').click();
cy.contains('TestClient').click();
-})
+});

MODIFY
manager/ui/war/cypress/support/index.js
manager/ui/war/cypress/support/index.js
// Import commands.js using ES2015 syntax:
import './commands'
+import './reset'
// Alternatively you can use CommonJS syntax:
// require('./commands')

ADD
manager/ui/war/cypress/support/reset.js
+Cypress.Commands.add('deleteOrg', (orgName) => {
+ const BASIC_AUTH = {
+ username: 'admin',
+ password: 'admin123!',
+ sendImmediately: true
+ };
+
+ // Unregister all clients in this org
+ cy.request({
+ url: `/apiman/organizations/${orgName}/clients`,
+ auth: BASIC_AUTH,
+ failOnStatusCode: false
+ })
+ .then(response => {
+ const clientList = response.body;
+ if (!Array.isArray(clientList)) {
+ return;
+ }
+ clientList.map(client => client.id)
+ .forEach(id => unregisterAllClients(orgName, id));
+ });
+
+ // Retire all API Versions in this org
+ cy.request({
+ url: `/apiman/organizations/${orgName}/apis`,
+ auth: BASIC_AUTH,
+ failOnStatusCode: false
+ })
+ .then(response => {
+ const apiList = response.body;
+ if (!Array.isArray(apiList)) {
+ return;
+ }
+ apiList.map(api => api.id)
+ .forEach(id => retireAllVersions(orgName, id));
+ });
+
+ cy.request({
+ method: 'DELETE',
+ url: `/apiman/organizations/${orgName}`,
+ auth: BASIC_AUTH,
+ failOnStatusCode: false
+ });
+
+ // -- Helpers
+
+ function retireAllVersions(orgName, apiId) {
+ cy.request({
+ url: `/apiman/organizations/${orgName}/apis/${apiId}/versions`,
+ auth: BASIC_AUTH,
+ failOnStatusCode: false
+ })
+ .then(response => {
+ const apiVersionsList = response.body || [];
+ for (let apiVersion in apiVersionsList) {
+ cy.request({
+ method: 'POST',
+ url: 'apiman/actions',
+ auth: BASIC_AUTH,
+ body: {
+ 'entityId': apiId,
+ 'entityVersion': apiVersion.version,
+ 'organizationId': orgName,
+ 'type': 'retireApi'
+ },
+ failOnStatusCode: false
+ });
+ }
+ });
+ }
+
+ function unregisterAllClients(orgName, clientId) {
+ cy.request({
+ url: `/apiman/organizations/${orgName}/clients/${clientId}/versions`,
+ auth: BASIC_AUTH
+ })
+ .then(response => {
+ const clientVersionList = response.body || [];
+ for (let clientVersion in clientVersionList) {
+ cy.request({
+ method: 'POST',
+ url: 'apiman/actions',
+ auth: BASIC_AUTH,
+ body: {
+ 'entityId': clientId,
+ 'entityVersion': clientVersion.version,
+ 'organizationId': orgName,
+ 'type': 'unregisterClient'
+ },
+ failOnStatusCode: false
+ });
+ }
+ });
+ }
+});

MODIFY
manager/ui/war/package.json
manager/ui/war/package.json
"@types/webpack-env": "^1.16.3",
"copy-webpack-plugin": "^9.1.0",
"css-loader": "^6.4.0",
- "cypress": "9.1.1",
+ "cypress": "9.5.4",
"glob": "^7.2.0",
"html-loader": "^3.1.0",
"html-webpack-plugin": "^5.3.2",

MODIFY
manager/ui/war/yarn.lock
manager/ui/war/yarn.lock
resolved "https://registry.yarnpkg.com/@braintree/sanitize-url/-/sanitize-url-5.0.2.tgz#b23080fa35520e993a8a37a0f5bca26aa4650a48"
integrity sha512-NBEJlHWrhQucLhZGHtSxM2loSaNUMajC7KOYJLyfcdW/6goVoff2HoYI3bz8YCDN0wKGbxtUL0gx2dvHpvnWlw==
+"@colors/colors@1.5.0":
+ version "1.5.0"
+ resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
+ integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==
+
"@cypress/request@^2.88.10":
version "2.88.10"
resolved "https://registry.yarnpkg.com/@cypress/request/-/request-2.88.10.tgz#b66d76b07f860d3a4b8d7a0604d020c662752cce"
"@types/mime" "^1"
"@types/node" "*"
-"@types/sinonjs__fake-timers@^6.0.2":
- version "6.0.4"
- resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-6.0.4.tgz#0ecc1b9259b76598ef01942f547904ce61a6a77d"
- integrity sha512-IFQTJARgMUBF+xVd2b+hIgXWrZEjND3vJtRCvIelcFB5SIXfjV4bOHbHJ0eXKh+0COrBRc8MqteKAz/j88rE0A==
+"@types/sinonjs__fake-timers@8.1.1":
+ version "8.1.1"
+ resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.1.tgz#b49c2c70150141a15e0fa7e79cf1f92a72934ce3"
+ integrity sha512-0kSuKjAS0TrGLJ0M/+8MaFkGsQhZpB6pxOmvS3K8FYI72K//YmdfoW9X2qPsAKh1mkwxGD5zib9s1FIFed6E8g==
"@types/sizzle@*", "@types/sizzle@^2.3.2":
version "2.3.3"
@@ -1037,7 +1042,7 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
-base64-js@^1.5.1:
+base64-js@^1.3.1, base64-js@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
@@ -1069,7 +1074,7 @@ blob-util@^2.0.2:
resolved "https://registry.yarnpkg.com/blob-util/-/blob-util-2.0.2.tgz#3b4e3c281111bb7f11128518006cdc60b403a1eb"
integrity sha512-T7JQa+zsXXEa6/8ZhHcQEW1UFfVM49Ts65uBkFL6fz2QmrElqmbajIDJvuA0tEhRe5eIjpV9ZF+0RfZR9voJFQ==
-bluebird@3.7.2:
+bluebird@^3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
@@ -1192,6 +1197,14 @@ buffer-indexof@^1.0.0:
resolved "https://registry.yarnpkg.com/buffer-indexof/-/buffer-indexof-1.1.1.tgz#52fabcc6a606d1a00302802648ef68f639da268c"
integrity sha512-4/rOEg86jivtPTeOUUT61jJO1Ya1TrR/OkqCSZDyq84WJh3LuuiphBYJN+fm5xufIk4XAFcEwte/8WzC8If/1g==
+buffer@^5.6.0:
+ version "5.7.1"
+ resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
+ integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
+ dependencies:
+ base64-js "^1.3.1"
+ ieee754 "^1.1.13"
+
bytes@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
@@ -1324,15 +1337,14 @@ cli-cursor@^3.1.0:
dependencies:
restore-cursor "^3.1.0"
-cli-table3@~0.6.0:
- version "0.6.0"
- resolved "https://registry.yarnpkg.com/cli-table3/-/cli-table3-0.6.0.tgz#b7b1bc65ca8e7b5cef9124e13dc2b21e2ce4faee"
- integrity sha512-gnB85c3MGC7Nm9I/FkiasNBOKjOiO1RNuXXarQms37q4QMpWdlbBgD/VnOStA2faG1dpXMv31RFApjX1/QdgWQ==
+cli-table3@~0.6.1:
+ version "0.6.2"
+ resolved "https://registry.yarnpkg.com/cli-table3/-/cli-table3-0.6.2.tgz#aaf5df9d8b5bf12634dc8b3040806a0c07120d2a"
+ integrity sha512-QyavHCaIC80cMivimWu4aWHilIpiDpfm3hGmqAmXVL1UsnbLuBSMd21hTX6VY4ZSDSM73ESLeF8TOYId3rBTbw==
dependencies:
- object-assign "^4.1.0"
string-width "^4.2.0"
optionalDependencies:
- colors "^1.1.2"
+ "@colors/colors" "1.5.0"
cli-truncate@^2.1.0:
version "2.1.0"
@@ -1373,11 +1385,6 @@ colorette@^2.0.10, colorette@^2.0.14:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.16.tgz#713b9af84fdb000139f04546bd4a93f62a5085da"
integrity sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==
-colors@^1.1.2:
- version "1.4.0"
- resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
- integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
-
combined-stream@^1.0.6, combined-stream@~1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
@@ -1595,24 +1602,25 @@ cssesc@^3.0.0:
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee"
integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==
-cypress@9.1.1:
- version "9.1.1"
- resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.1.1.tgz#26720ca5a22077cd85f49745616b7a08152a298f"
- integrity sha512-yWcYD8SEQ8F3okFbRPqSDj5V0xhrZBT5QRIH+P1J2vYvtEmZ4KGciHE7LCcZZLILOrs7pg4WNCqkj/XRvReQlQ==
+cypress@9.5.4:
+ version "9.5.4"
+ resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.5.4.tgz#49d9272f62eba12f2314faf29c2a865610e87550"
+ integrity sha512-6AyJAD8phe7IMvOL4oBsI9puRNOWxZjl8z1lgixJMcgJ85JJmyKeP6uqNA0dI1z14lmJ7Qklf2MOgP/xdAqJ/Q==
dependencies:
"@cypress/request" "^2.88.10"
"@cypress/xvfb" "^1.2.4"
"@types/node" "^14.14.31"
- "@types/sinonjs__fake-timers" "^6.0.2"
+ "@types/sinonjs__fake-timers" "8.1.1"
"@types/sizzle" "^2.3.2"
arch "^2.2.0"
blob-util "^2.0.2"
- bluebird "3.7.2"
+ bluebird "^3.7.2"
+ buffer "^5.6.0"
cachedir "^2.3.0"
chalk "^4.1.0"
check-more-types "^2.24.0"
cli-cursor "^3.1.0"
- cli-table3 "~0.6.0"
+ cli-table3 "~0.6.1"
commander "^5.1.0"
common-tags "^1.8.0"
dayjs "^1.10.4"
@@ -1631,15 +1639,15 @@ cypress@9.1.1:
listr2 "^3.8.3"
lodash "^4.17.21"
log-symbols "^4.0.0"
- minimist "^1.2.5"
+ minimist "^1.2.6"
ospath "^1.2.2"
pretty-bytes "^5.6.0"
proxy-from-env "1.0.0"
request-progress "^3.0.0"
+ semver "^7.3.2"
supports-color "^8.1.1"
tmp "~0.2.1"
untildify "^4.0.0"
- url "^0.11.0"
yauzl "^2.10.0"
d3@3.5.6:
@@ -2732,7 +2740,7 @@ icss-utils@^5.0.0, icss-utils@^5.1.0:
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-5.1.0.tgz#c6be6858abd013d768e98366ae47e25d5887b1ae"
integrity sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==
-ieee754@^1.2.1:
+ieee754@^1.1.13, ieee754@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==
@@ -3357,6 +3365,11 @@ minimist@^1.2.0, minimist@^1.2.5:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
+minimist@^1.2.6:
+ version "1.2.6"
+ resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
+ integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
+
mkdirp@^0.5.5:
version "0.5.5"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def"
@@ -4414,6 +4427,13 @@ selfsigned@^2.0.0:
dependencies:
node-forge "^1.2.0"
+semver@^7.3.2:
+ version "7.3.7"
+ resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
+ integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==
+ dependencies:
+ lru-cache "^6.0.0"
+
semver@^7.3.4, semver@^7.3.5:
version "7.3.5"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
@@ -5022,7 +5042,7 @@ url-parse@^1.5.2:
querystringify "^2.1.1"
requires-port "^1.0.0"
-url@^0.11.0, url@~0.11.0:
+url@~0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1"
integrity sha1-ODjpfPxgUh63PFJajlW/3Z4uKPE=

test(ui): add simple Organization deleter for Cypress #before test reset

Closes: #1933