Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/implement integration test system #736

Merged
merged 32 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d22749a
implement integration test system (WIP)
jihun Aug 20, 2024
85cd870
implement test specs (WIP)
jihun Aug 23, 2024
acac198
implement feedback integration test
jihun Sep 4, 2024
f857e51
implement channel integration test
jihun Sep 5, 2024
c16f438
implement project integration test
jihun Sep 5, 2024
184610e
implement user integration test
jihun Sep 9, 2024
315fbf6
implement issue integration test
jihun Sep 12, 2024
dacc050
cleaning test codes
jihun Sep 12, 2024
de93849
cleaning test codes
jihun Sep 12, 2024
cb884c2
Merge branch 'dev' into feat/implement-integration-test-system
jihun Sep 12, 2024
b38f939
add integration test
jihun Sep 12, 2024
1ec1026
add integration test npm script
jihun Sep 12, 2024
15f6597
change file name
jihun Sep 12, 2024
ddaa17e
fix test
jihun Sep 12, 2024
6f25f84
fix test
jihun Sep 12, 2024
86beef8
fix test
jihun Sep 12, 2024
ea28829
fix test
jihun Sep 12, 2024
b261358
change env variable location
jihun Sep 12, 2024
ee10ce2
fix test
jihun Sep 12, 2024
f2c0d42
fix test
jihun Sep 12, 2024
c817c84
fix test
jihun Sep 12, 2024
9ba5f1e
fix test
jihun Sep 12, 2024
1afaa20
fix test
jihun Sep 12, 2024
b249370
fix test
jihun Sep 12, 2024
b4f0ad1
fix test
jihun Sep 12, 2024
2f60871
fix test
jihun Sep 12, 2024
f28d6a0
fix test
jihun Sep 12, 2024
886d930
fix test
jihun Sep 12, 2024
b38aafd
change env variable location
jihun Sep 12, 2024
2538675
fix function name to deleteAllIndexes
jihun Sep 27, 2024
79d5be6
add a test step without opensearch
jihun Sep 27, 2024
77eeb89
fix lint error
jihun Sep 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Integration Tests

on:
pull_request:
branches: [dev, main]

jobs:
integration-test:
runs-on: ubuntu-latest

services:
mysql:
image: mysql:8.0.39
env:
MYSQL_ROOT_PASSWORD: userfeedback
MYSQL_DATABASE: e2e
MYSQL_USER: userfeedback
MYSQL_PASSWORD: userfeedback
TZ: UTC
ports:
- 13307:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3

smtp:
image: rnwood/smtp4dev:v3
ports:
- 5080:80
- 25:25
- 143:143

opensearch:
image: opensearchproject/opensearch:2.16.0
env:
discovery.type: single-node
bootstrap.memory_lock: "true"
plugins.security.disabled: "true"
OPENSEARCH_INITIAL_ADMIN_PASSWORD: "UserFeedback123!@#"
options: >-
--health-cmd="curl -s http://localhost:9200/_cluster/health | grep -q '\"status\":\"green\"'"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 9200:9200

steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Setup integration test (with opensearch)
run: |
npx corepack enable
pnpm install --frozen-lockfile
pnpm build
echo "BASE_URL=http://localhost:3000" >> ./apps/api/.env
echo "JWT_SECRET=DEV" >> ./apps/api/.env
echo "OPENSEARCH_USE=true" >> ./apps/api/.env
echo "OPENSEARCH_NODE=http://localhost:9200" >> ./apps/api/.env
echo "OPENSEARCH_USERNAME=''" >> ./apps/api/.env
echo "OPENSEARCH_PASSWORD=''" >> ./apps/api/.env

- name: Run integration tests (with opensearch)
run: |
npm run test:integration

- name: Setup integration test (without opensearch)
run: |
echo "OPENSEARCH_USE=false" >> ./apps/api/.env

- name: Run integration tests (without opensearch)
run: |
npm run test:integration
jihun marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions apps/api/integration-test/database-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright 2023 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
import mysql from 'mysql2/promise';

export async function createConnection() {
return await mysql.createConnection({
host: '127.0.0.1',
port: 13307,
user: 'root',
password: 'userfeedback',
});
}
61 changes: 61 additions & 0 deletions apps/api/integration-test/global.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright 2023 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
import { join } from 'path';
import { createConnection } from 'typeorm';
import { SnakeNamingStrategy } from 'typeorm-naming-strategies';

import { createConnection as connect } from './database-utils';

process.env.NODE_ENV = 'test';
process.env.MYSQL_PRIMARY_URL =
'mysql://root:userfeedback@localhost:13307/integration';
process.env.MASTER_API_KEY = 'master-api-key';

async function createTestDatabase() {
const connection = await connect();

await connection.query(`DROP DATABASE IF EXISTS integration;`);
await connection.query(`CREATE DATABASE IF NOT EXISTS integration;`);
await connection.end();
}

async function runMigrations() {
const connection = await createConnection({
type: 'mysql',
host: '127.0.0.1',
port: 13307,
username: 'root',
password: 'userfeedback',
database: 'integration',
migrations: [
join(
__dirname,
'../src/configs/modules/typeorm-config/migrations/*.{ts,js}',
),
],
migrationsTableName: 'migrations',
namingStrategy: new SnakeNamingStrategy(),
timezone: '+00:00',
});

await connection.runMigrations();
await connection.close();
}

module.exports = async () => {
await createTestDatabase();
await runMigrations();
};
27 changes: 27 additions & 0 deletions apps/api/integration-test/global.teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2023 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
import { createConnection as connect } from './database-utils';

async function dropTestDatabase() {
const connection = await connect();

await connection.query(`DROP DATABASE IF EXISTS integration;`);
await connection.end();
}

module.exports = async () => {
await dropTestDatabase();
};
18 changes: 18 additions & 0 deletions apps/api/integration-test/jest-integration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"displayName": "api-integration",
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"moduleNameMapper": {
"^@/(.*)$": ["<rootDir>/../src/$1"]
},
"testRegex": ".integration-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"setupFilesAfterEnv": [
"<rootDir>/../integration-test/jest-integration.setup.ts"
],
"globalSetup": "<rootDir>/../integration-test/global.setup.ts",
"globalTeardown": "<rootDir>/../integration-test/global.teardown.ts"
}
20 changes: 20 additions & 0 deletions apps/api/integration-test/jest-integration.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright 2023 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
jest.mock('@nestjs-modules/mailer/dist/adapters/handlebars.adapter', () => {
return {
HandlebarsAdapter: jest.fn(),
};
});
Loading
Loading