From 7d8e5f291fdf8e56be1e7d82418673ffbd960fe2 Mon Sep 17 00:00:00 2001 From: David Ma <40131297+davidma415@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:21:55 -0700 Subject: [PATCH] test: add tests for scope select (#311) --- .../specs/application_registration.spec.ts | 137 +++++++++++++++++- cypress/e2e/support/index.ts | 1 + cypress/e2e/support/mock-commands.ts | 20 ++- src/components/ViewSpecRegistrationModal.vue | 4 +- yarn.lock | 4 +- 5 files changed, 157 insertions(+), 9 deletions(-) diff --git a/cypress/e2e/specs/application_registration.spec.ts b/cypress/e2e/specs/application_registration.spec.ts index 61543fa9..3f84697b 100644 --- a/cypress/e2e/specs/application_registration.spec.ts +++ b/cypress/e2e/specs/application_registration.spec.ts @@ -169,8 +169,6 @@ describe('Application Registration', () => { cy.get(submitButton).click() - - cy.wait('@postApplicationRegistration').then(() => { cy.get('[data-testid="copy-secret-modal"]').should('exist') cy.get('[data-testid="copy-button"]').eq(0).should('exist').should('contain', 'your-client-id') @@ -526,6 +524,141 @@ describe('Application Registration', () => { ) }) + it('does not show select available scopes if no scopes are available - feature flag on', () => { + cy.mockProductDocument() + cy.mockProduct() + cy.mockLaunchDarklyFlags([ + { + name: 'tdx-3460-developer-managed-scopes', + value: true + } + ]) + cy.mockProductVersionApplicationRegistration(versions[0]) + cy.mockGetProductDocuments(product.id) + cy.mockProductOperations(product.id, versions[0].id) + cy.mockProductVersionSpec(product.id, versions[0].id) + cy.mockRegistrations('*', []) // mock with empty so that we add one. + + cy.viewport(1440, 900) + cy.visit(`/spec/${product.id}`) + cy.get('.swagger-ui', { timeout: 12000 }) + + cy.mockApplications(apps, 4) + cy.mockProductVersionAvailableRegistrations(product.id, versions[0].id, apps) + + cy.get('[data-testid="register-button"]', { timeout: 12000 }).click() + cy.get(selectors.appRegModal).should('exist') + cy.get(`${selectors.appRegModal} [data-testid="register-${apps[0].name}"]`).should('contain', apps[0].name).click() + cy.get('[data-testid="available-scopes-select"]').should('not.exist') + }) + it('does show select available scopes if scopes are available - feature flag on', () => { + cy.mockProductDocument() + cy.mockProduct(product.id, product) + cy.mockLaunchDarklyFlags([ + { + name: 'tdx-3460-developer-managed-scopes', + value: true + } + ]) + cy.mockProductVersionApplicationRegistration(versions[0]) + // Update the version to include registration config + const productVersionWithScopes = versions[0] + + productVersionWithScopes.registration_configs = [ + { + name: 'openid-connect', + available_scopes: [ + 'scope1', + 'scope2' + ] + } + ] + cy.mockProductVersion(product.id, versions[0].id, productVersionWithScopes) + cy.mockGetProductDocuments(product.id) + cy.mockProductOperations(product.id, versions[0].id) + cy.mockProductVersionSpec(product.id, versions[0].id) + cy.mockRegistrations('*', []) // mock with empty so that we add one. + + cy.viewport(1440, 900) + cy.visit(`/spec/${product.id}`) + cy.get('.swagger-ui', { timeout: 12000 }) + + cy.mockApplications(apps, 4) + cy.mockProductVersionAvailableRegistrations(product.id, versions[0].id, apps) + + cy.get('[data-testid="register-button"]', { timeout: 12000 }).click() + cy.get(selectors.appRegModal).should('exist') + cy.get(`${selectors.appRegModal} [data-testid="register-${apps[0].name}"]`).should('contain', apps[0].name).click() + cy.get('.available-scopes-select').should('exist') + }) + it('does not show select available scopes if scopes are available - feature flag off', () => { + cy.mockProductDocument() + cy.mockProduct(product.id, product) + cy.mockLaunchDarklyFlags([ + { + name: 'tdx-3460-developer-managed-scopes', + value: false + } + ]) + cy.mockProductVersionApplicationRegistration(versions[0]) + // Update the version to include registration config + const productVersionWithScopes = versions[0] + + productVersionWithScopes.registration_configs = [ + { + name: 'openid-connect', + available_scopes: [ + 'scope1', + 'scope2' + ] + } + ] + cy.mockProductVersion(product.id, versions[0].id, productVersionWithScopes) + cy.mockGetProductDocuments(product.id) + cy.mockProductOperations(product.id, versions[0].id) + cy.mockProductVersionSpec(product.id, versions[0].id) + cy.mockRegistrations('*', []) // mock with empty so that we add one. + + cy.viewport(1440, 900) + cy.visit(`/spec/${product.id}`) + cy.get('.swagger-ui', { timeout: 12000 }) + + cy.mockApplications(apps, 4) + cy.mockProductVersionAvailableRegistrations(product.id, versions[0].id, apps) + + cy.get('[data-testid="register-button"]', { timeout: 12000 }).click() + cy.get(selectors.appRegModal).should('exist') + cy.get(`${selectors.appRegModal} [data-testid="register-${apps[0].name}"]`).should('contain', apps[0].name).click() + cy.get('.available-scopes-select').should('not.exist') + }) + it('does not show select available scopes if feature flag off', () => { + cy.mockProductDocument() + cy.mockProduct() + cy.mockLaunchDarklyFlags([ + { + name: 'tdx-3460-developer-managed-scopes', + value: false + } + ]) + cy.mockProductVersionApplicationRegistration(versions[0]) + cy.mockGetProductDocuments(product.id) + cy.mockProductOperations(product.id, versions[0].id) + cy.mockProductVersionSpec(product.id, versions[0].id) + cy.mockRegistrations('*', []) // mock with empty so that we add one. + + cy.viewport(1440, 900) + cy.visit(`/spec/${product.id}`) + cy.get('.swagger-ui', { timeout: 12000 }) + + cy.mockApplications(apps, 4) + cy.mockProductVersionAvailableRegistrations(product.id, versions[0].id, apps) + + cy.get('[data-testid="register-button"]', { timeout: 12000 }).click() + cy.get(selectors.appRegModal).should('exist') + cy.get(`${selectors.appRegModal} [data-testid="register-${apps[0].name}"]`).should('contain', apps[0].name).click() + cy.get('[data-testid="available-scopes-select"]').should('not.exist') + }) + it('can request registration to a product and is directed to application upon auto_approval', () => { cy.mockProductDocument() cy.mockProduct() diff --git a/cypress/e2e/support/index.ts b/cypress/e2e/support/index.ts index 1010215c..39d3bb2f 100644 --- a/cypress/e2e/support/index.ts +++ b/cypress/e2e/support/index.ts @@ -24,6 +24,7 @@ declare global { mockProductDocumentTree(productId?: string, options?: Partial & {body: any}): Chainable> mockProductApiDocument(productId?: string, options?: Partial & {body: any}): Chainable> mockProduct(productId?: string, mockProduct?: Product, mockVersions?: ProductVersion[]): Chainable> + mockProductVersion(productId?: string, versionId?: string, mockVersion?: ProductVersion): Chainable> mockApplications(searchResults?: Array, totalCount?: number, pageSize?: number, pageNumber?: number): Chainable> mockApplicationWithCredAndReg(data: GetApplicationResponse, credentials?: ListCredentialsResponseDataInner[], registrations?: Array): Chainable>, mockContextualAnalytics(): Chainable> diff --git a/cypress/e2e/support/mock-commands.ts b/cypress/e2e/support/mock-commands.ts index 0ce8cff0..01c58316 100644 --- a/cypress/e2e/support/mock-commands.ts +++ b/cypress/e2e/support/mock-commands.ts @@ -7,7 +7,7 @@ import document from '../fixtures/dochub_mocks/document.json' import documentTreeJson from '../fixtures/dochub_mocks/documentTree.json' import apiDocumentationJson from '../fixtures/dochub_mocks/parentApiDocumentation.json' import petstoreOperationsV2 from '../fixtures/v2/petstoreOperations.json' -import { +import { GetApplicationResponse, ListApplicationsResponse, ListCredentialsResponse, @@ -18,11 +18,12 @@ import { Product, ProductDocument, ProductDocumentRaw, + ProductVersion, ProductVersionListPage, ProductVersionSpecDocument, ProductVersionSpecOperations, ProductVersionSpecOperationsOperationsInner, - SearchResults + SearchResults } from '@kong/sdk-portal-js' import { THEMES } from '../fixtures/theme.constant' @@ -68,6 +69,7 @@ Cypress.Commands.add('mockAppearance', (appearance = {}) => { } } } + cy.mockLogo() cy.mockCatalogCover() @@ -535,6 +537,18 @@ Cypress.Commands.add('mockGetProductDocumentTree', (productId) => { ).as('ProductDocumentTree') }) +Cypress.Commands.add('mockProductVersion', (productId = '*', versionId = '*', version = versions[0]) => { + const versionResponse: ProductVersion = { + ...version + } + + cy.intercept('get', `**/api/v2/products/${productId}/versions/${versionId}`, { + statusCode: 200, + delay: 100, + body: versionResponse + }).as('productVersion') +}) + Cypress.Commands.add('mockProductVersionSpec', (productId = '*', versionId = '*', content = JSON.stringify(petstoreJson30)) => { const specResponse: ProductVersionSpecDocument = { api_type: 'openapi', @@ -549,7 +563,7 @@ Cypress.Commands.add('mockProductVersionSpec', (productId = '*', versionId = '*' Cypress.Commands.add('mockProductOperations', (productId = '*', versionId = '*', operations = petstoreOperationsV2.operations as ProductVersionSpecOperationsOperationsInner[]) => { const operationsResponse: ProductVersionSpecOperations = { api_type: 'openapi', - operations: operations + operations } cy.intercept('get', `**/api/v2/products/${productId}/versions/${versionId}/spec/operations`, { diff --git a/src/components/ViewSpecRegistrationModal.vue b/src/components/ViewSpecRegistrationModal.vue index 507ef7d4..1aedb706 100644 --- a/src/components/ViewSpecRegistrationModal.vue +++ b/src/components/ViewSpecRegistrationModal.vue @@ -62,8 +62,8 @@ v-if="availableScopes.length" v-model="selectedScopes" :label="helpText.applicationRegistration.availableScopesLabel" - data-testid="analytics-service-filter" - class="analytics-service-filter" + data-testid="available-scopes-select" + class="available-scopes-select" :items="mappedAvailableScopes" @change="handleChangedItem" /> diff --git a/yarn.lock b/yarn.lock index 1a7fc3b2..87df1f78 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3211,7 +3211,7 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.12.0.tgz#ce1c9d143389679e253b314241ea9aa5cec980d3" integrity sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg== -axios@1.6.0, axios@^1.4.0: +axios@1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.0.tgz#f1e5292f26b2fd5c2e66876adc5b06cdbd7d2102" integrity sha512-EZ1DYihju9pwVB+jg67ogm+Tmqc6JmhamRN6I4Zt8DfZu5lbcQGw3ozH9lFejSJgs/ibaef3A9PMXPLeefFGJg== @@ -11428,7 +11428,7 @@ uuid@^8.0.0, uuid@^8.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== -uuid@^9.0.1: +uuid@^9.0.0, uuid@^9.0.1: version "9.0.1" resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30" integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==