Skip to content

Commit

Permalink
Merge pull request #1036 from bcgov/test
Browse files Browse the repository at this point in the history
Create Latest Release
  • Loading branch information
rustyjux authored Apr 16, 2024
2 parents 73d0b1b + a9958fd commit 00556ce
Show file tree
Hide file tree
Showing 16 changed files with 471 additions and 38 deletions.
22 changes: 13 additions & 9 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ Install Cypress on your local machine by following [these instructions](https://
- Clone the API Service Portal repository
- Run `./e2e $ npm i` to install all the dependencies

### Test data dependencies

Many tests cannot be run independently because they depend on state established by other tests. These dependencies are [documented](test-data-dependencies.md) to assist in running tests selectively.

### Running Cypress Locally

- `./e2e/cypress.json` contains the web app config. Update the file to use local or dev version of the portal for executing the tests
- `./e2e/cypress.config.ts` contains the web app config. Update the file to use local or dev version of the portal for executing the tests

- Recommendation is to use local version of portal. Use `docker-compose` to create local development environment
- Recommendation is to use local version of portal. Use `docker compose` to create local development environment

#### Cypress Test Runner

Expand All @@ -52,14 +56,14 @@ Install Cypress on your local machine by following [these instructions](https://

### Docker Compose

- Run `docker-compose up` to spin up a local development environment, which includes Cypress as one of the services and it executes all the tests and generates the HTML report
- Run `docker-compose down` to tear down the environment
- Run `docker compose up` to spin up a local development environment, which includes Cypress as one of the services and it executes all the tests and generates the HTML report
- Run `docker compose down` to tear down the environment

#### GitHub Actions

- Any new commit pushed to `util/*automation*` branch triggers job (`.github/workflows/aps-cypress-e2e.yaml`) and it spawns all the services including cypress to execute the test suite
- Any new commit pushed to a `cypress*` branch or `test`, triggers the job (`.github/workflows/aps-cypress-e2e.yaml`) and it spawns all the services including Cypress to execute the test suite

- The test results would be uploaded to `https://www.cypress.io/dashboard/`
- The test results would be uploaded to `https://www.cypress.io/dashboard/`, as well as attached as an artifact on the GitHub Action run.

## 3. Cypress on Windows

Expand All @@ -85,7 +89,7 @@ WSL 2 or your local machine are prefaced with `WSL` and `LM` respectively in the

### `WSL`: Build and Run Dev Environment

- Inside the `api-services-portal` directory, build and run the application by running `docker-compose up` at the project root.
- Inside the `api-services-portal` directory, build and run the application by running `docker compose up` at the project root.

### `LM`: Install E2E Testing Dependencies

Expand All @@ -97,13 +101,13 @@ WSL 2 or your local machine are prefaced with `WSL` and `LM` respectively in the

## 4. Creating Tests

After you run `npm run cy:open`, the Cypress console will open. Before continuing, ensure the `Electron` browser is selected from the drop-down list of available browsers (top-right corner of the Cypress test runner).
After you run `npm run cy:open`, the Cypress console will open. Before continuing, ensure the `Edge` browser is selected from the drop-down list of available browsers (top-right corner of the Cypress test runner).

Each test file defined in the `./e2e/cypress/tests` directory will be visible. Click on a test in order to run all test cases in that file. A new browser window will open and you will see your tests executed sequentially.

### Test File Naming Convention and Location

- Test files follow this naming convention: `<num>-<test-name>.spec.ts`. (e.g., `01-create-api.spec.ts`)
- Test files follow this naming convention: `<num>-<test-name>.cy.ts`. (e.g., `01-create-api.cy.ts`)
- Store the test files in the `./e2e/cypress/tests` directory.

### Test File Structure
Expand Down
11 changes: 10 additions & 1 deletion e2e/cypress/fixtures/apiowner.json
Original file line number Diff line number Diff line change
Expand Up @@ -782,5 +782,14 @@
},
"activityAt": "2022-09-20T20:37:30.570Z"
}
]
],
"twoTieredHidden": {
"product": {
"name": "Two Tiered Hidden Product",
"serviceName": "two-tier-service",
"environment": {
"name": "dev"
}
}
}
}
3 changes: 3 additions & 0 deletions e2e/cypress/fixtures/common-testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,8 @@
"apiTest": {
"namespace": "gw-c3f31",
"delete_namespace": "testplatform"
},
"twoTieredHidden": {
"namespace": "two-tier-hidden"
}
}
79 changes: 79 additions & 0 deletions e2e/cypress/fixtures/tthidden-jwt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
kind: Namespace
name: two-tier-hidden
displayName: two-tier-hidden Display Name
---
kind: GatewayService
name: two-tier-service-dev
tags: [ns.two-tier-hidden]
host: httpbin.org
port: 443
protocol: https
retries: 0
routes:
- name: two-tier-service-dev
tags: [ns.two-tier-hidden]
hosts:
- two-tier-service.dev.api.gov.bc.ca
methods:
- GET
strip_path: false
https_redirect_status_code: 426
path_handling: v0
request_buffering: true
response_buffering: true
plugins:
- name: jwt-keycloak
tags: [ns.two-tier-hidden, aps.two-tiered-hidden]
enabled: true
config:
allowed_iss:
- https://dev.loginproxy.gov.bc.ca/auth/realms/apigw
allowed_aud: ap-two-tier-hidden-default-dev
run_on_preflight: true
iss_key_grace_period: 10
maximum_expiration: 0
algorithm: RS256
claims_to_verify:
- exp
uri_param_names:
- jwt
cookie_names: []
scope: null
roles: null
realm_roles: null
client_roles: null
anonymous: ce26955a-cf08-4907-9427-12d01c8bd94c
consumer_match: true
consumer_match_claim: azp
consumer_match_claim_custom_id: true
consumer_match_ignore_not_found: false
- name: request-transformer
tags: [ns.two-tier-hidden]
enabled: true
config:
http_method: null
---
kind: DraftDataset
name: two-tier-service-dataset
title: Two-tier-service
organization: ministry-of-health
organizationUnit: public-health
notes: Some information about the two-tier-service service
tags: [two-tier-service, openapi]
license_title: Access Only
view_audience: Government
security_class: LOW-PUBLIC
record_publish_date: '2021-05-27'
---
kind: Product
name: Two Tiered Hidden Product
appId: 'LFH78YU956RE'
dataset: two-tier-service-dataset
environments:
- name: dev
active: true
approval: false
flow: kong-api-key-acl
appId: '506CB7CF'
services: [two-tier-service-dev]

62 changes: 62 additions & 0 deletions e2e/cypress/fixtures/tthidden-key-auth.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
kind: Namespace
name: two-tier-hidden
displayName: two-tier-hidden Display Name
---
kind: GatewayService
name: two-tier-service-dev
tags: [ns.two-tier-hidden]
host: httpbin.org
port: 443
protocol: https
retries: 0
routes:
- name: two-tier-service-dev
tags: [ns.two-tier-hidden]
hosts:
- two-tier-service.dev.api.gov.bc.ca
methods:
- GET
strip_path: false
https_redirect_status_code: 426
path_handling: v0
request_buffering: true
response_buffering: true
plugins:
- name: key-auth
tags: [ ns.two-tier-hidden, aps.two-tiered-hidden ]
protocols: [ http, https ]
config:
key_names: ["X-API-KEY"]
run_on_preflight: true
hide_credentials: true
key_in_body: false
anonymous: ce26955a-cf08-4907-9427-12d01c8bd94c
- name: acl
tags: [ ns.two-tier-hidden ]
config:
hide_groups_header: true
allow: [ "406CB7CF" ]
---
kind: DraftDataset
name: two-tier-service-dataset
title: Two-tier-service
organization: ministry-of-health
organizationUnit: public-health
notes: Some information about the two-tier-service service
tags: [two-tier-service, openapi]
license_title: Access Only
view_audience: Government
security_class: LOW-PUBLIC
record_publish_date: '2021-05-27'
---
kind: Product
name: Two Tiered Hidden Product
appId: 'LFH78YU956RE'
dataset: two-tier-service-dataset
environments:
- name: dev
active: true
approval: false
flow: kong-api-key-acl
appId: '506CB7CF'
services: [two-tier-service-dev]
11 changes: 11 additions & 0 deletions e2e/cypress/pageObjects/apiDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ class ApiDirectoryPage {
cy.get(ele).should('exist')
}

checkTwoTieredIcon(productName: string) {
const pname: string = productName.toLowerCase().replaceAll(' ', '-')
var ele: string = `[data-testid=two-tiered-icon-${pname}]`
cy.get(ele).should('exist')
}

checkTwoTieredHiddenButton() {
var ele: string = '[data-testid=request-access-button-two-tiered-hidden]'
cy.get(ele).should('exist')
}

addOrganizationAndOrgUnit(product: any) {
cy.contains('button', 'Add Organization').click({ force: true })
cy.get(this.orgDropDown).select(product.orgName)
Expand Down
12 changes: 6 additions & 6 deletions e2e/cypress/tests/07-manage-control/02-rate-limiting.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ describe('Manage Control-Rate Limiting Spec for Service as Scope and Local Polic
cy.get('@apiowner').then(({ product }: any) => {
cy.makeKongRequest(product.environment.config.serviceName, 'GET').then((response) => {
expect(response.status).to.be.equal(200)
})
cy.makeKongRequest(product.environment.config.serviceName, 'GET').then((response) => {
expect(response.status).to.be.equal(429)
expect(response.body.message).to.be.contain('API rate limit exceeded')
})
cy.makeKongRequest(product.environment.config.serviceName, 'GET').then((response) => {
expect(response.status).to.be.equal(429)
expect(response.body.message).to.be.contain('API rate limit exceeded')
})
})
})
})
})
Expand Down Expand Up @@ -273,4 +273,4 @@ describe('Manage Control-Apply Rate limiting to Global and Consumer at Route lev
after(() => {
cy.logout()
})
})
})
Loading

0 comments on commit 00556ce

Please sign in to comment.