Skip to content

Commit

Permalink
Merge pull request #811 from line/dev
Browse files Browse the repository at this point in the history
release: 6.2441.69
  • Loading branch information
jihun authored Oct 10, 2024
2 parents 6eb6631 + 3768377 commit 5600f9f
Show file tree
Hide file tree
Showing 47 changed files with 4,684 additions and 2,529 deletions.
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.17.1
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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.17.0
20.18.0
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

0 comments on commit 5600f9f

Please sign in to comment.