Skip to content

Commit

Permalink
test: add tests for scope select (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidma415 authored Nov 16, 2023
1 parent 6a7eb8c commit 7d8e5f2
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 9 deletions.
137 changes: 135 additions & 2 deletions cypress/e2e/specs/application_registration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ declare global {
mockProductDocumentTree(productId?: string, options?: Partial<TypeOptions> & {body: any}): Chainable<JQuery<HTMLElement>>
mockProductApiDocument(productId?: string, options?: Partial<TypeOptions> & {body: any}): Chainable<JQuery<HTMLElement>>
mockProduct(productId?: string, mockProduct?: Product, mockVersions?: ProductVersion[]): Chainable<JQuery<HTMLElement>>
mockProductVersion(productId?: string, versionId?: string, mockVersion?: ProductVersion): Chainable<JQuery<HTMLElement>>
mockApplications(searchResults?: Array<GetApplicationResponse>, totalCount?: number, pageSize?: number, pageNumber?: number): Chainable<JQuery<HTMLElement>>
mockApplicationWithCredAndReg(data: GetApplicationResponse, credentials?: ListCredentialsResponseDataInner[], registrations?: Array<GetRegistrationResponse>): Chainable<JQuery<HTMLElement>>,
mockContextualAnalytics(): Chainable<JQuery<HTMLElement>>
Expand Down
20 changes: 17 additions & 3 deletions cypress/e2e/support/mock-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'

Expand Down Expand Up @@ -68,6 +69,7 @@ Cypress.Commands.add('mockAppearance', (appearance = {}) => {
}
}
}

cy.mockLogo()
cy.mockCatalogCover()

Expand Down Expand Up @@ -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',
Expand All @@ -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`, {
Expand Down
4 changes: 2 additions & 2 deletions src/components/ViewSpecRegistrationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit 7d8e5f2

Please sign in to comment.