Skip to content

Commit

Permalink
adds local-only integration test for s3
Browse files Browse the repository at this point in the history
  • Loading branch information
jduss4 committed Aug 30, 2024
1 parent 93260b9 commit bff5fea
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .env.test.example.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
S3_ACCESS_KEY_ID=
S3_ACCESS_KEY_SECRET=
S3_BUCKET=
S3_REGION=
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ In order to try out UAA, you will need to comment out your CF_API_TOKEN and then

### Step 6: Testing

To run the entire test suite, you will need to start the docker database container:
To run the entire unit test suite, you will need to start the docker database container:

```bash
cd cgui-db-docker
docker compose up
```

To run the entire test suite:
Run the suite:

```bash
npm test
Expand All @@ -185,6 +185,20 @@ To run test files matching certain text (one example):
npm test -- serverside
```

#### Integration testing

We have one test that runs against the s3 bucket to test that updates to the AWS libraries have not broken the connection. This test runs locally and is not part of the CI pipeline. To run this test, set up a local-only test environment file. This file should not be tracked in version control:

```bash
cp .env.test.example.local .env.test.local
```

Then, if you have not already, set up a [s3 service key](#s3-user-information). Copy the values into `.env.test.local`. To run the test:

```bash
npm run test:integration
```

### Step 7: Committing

#### Preparing your code
Expand Down
21 changes: 21 additions & 0 deletions __tests__/api/aws/s3.test.integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import nock from 'nock';
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
import { getUserLogonInfo } from '@/api/aws/s3';

describe('s3 integration tests', () => {
beforeAll(() => {
// allow connection to AWS
nock.enableNetConnect('amazonaws.com');
});

afterAll(() => {
// disable network connections in case other tests are being run with this file
nock.disableNetConnect();
});

it('connects to the bucket and retrieves the user logon info file', async () => {
const info = await getUserLogonInfo();
expect(info).toBeDefined();
expect(info.user_summary).toBeDefined();
});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dev": "next dev",
"dev-cf": "./token-refresh.sh; next dev",
"start": "next start",
"test": "jest",
"test": "jest --testPathPattern=test\\.js",
"test:integration": "jest --testPathPattern=integration\\.js --collectCoverage=false",
"lint": "next lint",
"format": "prettier --check '**/*.{js,jsx,ts,tsx}'",
"format:fix": "prettier --write '**/*.{js,jsx,ts,tsx}'"
Expand Down

0 comments on commit bff5fea

Please sign in to comment.