Skip to content

Commit

Permalink
working on tests db connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Mar 6, 2024
1 parent c6328f4 commit 9e9f537
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 35 deletions.
34 changes: 16 additions & 18 deletions __tests__/integration/memberActivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ import { Connection } from 'mongoose';
setupTestDB();

describe('member-activity routes', () => {
let connection: Connection;
beforeAll(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
});
afterAll(async () => {
await connection.close();
});
beforeEach(async () => {
cleanUpTenantDatabases();
userOne.communities = [communityOne._id];
Expand All @@ -40,9 +47,8 @@ describe('member-activity routes', () => {
platformFour.community = communityOne._id;
});
describe('POST /api/v1/member-activity/:platformId/active-members-composition-line-graph', () => {
let connection: Connection;
beforeEach(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
cleanUpTenantDatabases();
});
test('should return 200 and active members composition line graph data if req data is ok', async () => {
await insertCommunities([communityOne]);
Expand Down Expand Up @@ -135,9 +141,8 @@ describe('member-activity routes', () => {
});

describe('POST /api/v1/member-activity/:platformId/disengaged-members-composition-line-graph', () => {
let connection: Connection;
beforeEach(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
cleanUpTenantDatabases();
});
test('should return 200 and disengaged members composition line graph data if req data is ok', async () => {
await insertCommunities([communityOne]);
Expand Down Expand Up @@ -226,9 +231,8 @@ describe('member-activity routes', () => {
});

describe('POST /api/v1/member-activity/:platformId/active-members-onboarding-line-graph', () => {
let connection: Connection;
beforeEach(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
cleanUpTenantDatabases();
});
test('should return 200 and active members onboarding line graph data if req data is ok', async () => {
await insertCommunities([communityOne]);
Expand Down Expand Up @@ -314,9 +318,8 @@ describe('member-activity routes', () => {
});

describe('POST /api/v1/member-activity/:platformId/inactive-members-line-graph', () => {
let connection: Connection;
beforeEach(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
cleanUpTenantDatabases();
});
test('should return 200 and inactive members line graph data if req data is ok', async () => {
await insertCommunities([communityOne]);
Expand Down Expand Up @@ -474,9 +477,8 @@ describe('member-activity routes', () => {
// })

describe('GET /api/v1/member-activity/:platformId/fragmentation-score', () => {
let connection: Connection;
beforeEach(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
cleanUpTenantDatabases();
});
test('should return 200 and fragmentation score if req data is ok', async () => {
await insertCommunities([communityOne]);
Expand Down Expand Up @@ -631,9 +633,8 @@ describe('member-activity routes', () => {
});

describe('GET /api/v1/member-activity/:platformId/decentralisation-score', () => {
let connection: Connection;
beforeEach(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
cleanUpTenantDatabases();
});
test('should return 200 and decentralisation score if req data is ok', async () => {
await insertCommunities([communityOne]);
Expand Down Expand Up @@ -808,9 +809,8 @@ describe('member-activity routes', () => {
});

describe('POST /api/v1/member-activity/:platformId/active-members-composition-table', () => {
let connection: Connection;
beforeEach(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
cleanUpTenantDatabases();
});
test('should return 200 and apply the default query options', async () => {
await insertCommunities([communityOne]);
Expand Down Expand Up @@ -1258,9 +1258,8 @@ describe('member-activity routes', () => {
});

describe('POST /api/v1/member-activity/:platformId/active-members-onboarding-table', () => {
let connection: Connection;
beforeEach(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
cleanUpTenantDatabases();
});
test('should return 200 and apply the default query options', async () => {
await insertUsers([userOne]);
Expand Down Expand Up @@ -1711,9 +1710,8 @@ describe('member-activity routes', () => {
});

describe('POST /api/v1/member-activity/:platformId/disengaged-members-composition-table', () => {
let connection: Connection;
beforeEach(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
cleanUpTenantDatabases();
});
test('should return 200 and apply the default query options', async () => {
await insertUsers([userOne]);
Expand Down
7 changes: 0 additions & 7 deletions __tests__/utils/setupTestDB.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import mongoose from 'mongoose';
import config from '../../src/config';
import RabbitMQ, { MBConnection, Queue } from '@togethercrew.dev/tc-messagebroker';
import Redis from 'ioredis';
import { platformOne, platformTwo, platformThree, platformFour } from '../fixtures/platform.fixture';
import { DatabaseManager } from '@togethercrew.dev/db';

Expand Down Expand Up @@ -38,12 +37,6 @@ const setupTestDB = () => {

afterAll(async () => {
await mongoose.disconnect();
const redis = new Redis({
host: config.redis.host,
port: config.redis.port,
password: config.redis.password,
});
await redis.disconnect();
});
};

Expand Down
77 changes: 67 additions & 10 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,68 @@ services:
app:
build:
context: .
target: dev
target: development
dockerfile: Dockerfile
environment:
- NODE_ENV=test
- NODE_ENV=development
- PORT=3000
- DB_HOST=mongo
- DB_PORT=27017
- DB_USER=root
- DB_PASSWORD=pass
- DB_NAME=RnDAO
- DISCORD_CLIENT_ID=1
- DISCORD_CLIENT_SECRET=1
- SENTRY_DSN=1
- SENTRY_ENV=test
- DISCORD_BOT_TOKEN=1
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_PASSWORD=
- RABBIT_HOST=localhost
- RABBIT_HOST=rabbitmq
- RABBIT_PORT=5672
- RABBIT_USER=root
- RABBIT_PASSWORD=pass
- LOG_LEVEL=info
- PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040
- NEO4J_PROTOCOL=bolt
- NEO4J_HOST=neo4j
- NEO4J_PORT=7687
- NEO4J_USER=neo4j
- NEO4J_PASSWORD=password
- NEO4J_DB=neo4j
- SENTRY_DSN=https://791ed14c7dc84377a291ba2dd60270bb@o4505110094282752.ingest.sentry.io/4505158976733184
- SENTRY_ENV=development
- DISCORD_AUTHORIZE_CALLBACK_URI=empty
- DISCORD_CONNECT_CALLBACK_URI=empty
- DISCORD_REQUEST_ACCESS_CALLBACK_URI=empty
- TWITTER_CONNECT_CALLBACK_URI=empty
- TWITTER_CLIENT_ID=empty
- TWITTER_CLIENT_SECRET=empty
- DISCORD_CLIENT_ID=empty
- DISCORD_CLIENT_SECRET=empty
- DISCORD_BOT_TOKEN=empty
- JWT_SECRET=0%55e*enmvbfm@@u7v9+amg-ju_d_safeasdf6(v*88h4$#h&o-i7ste#tv*hx
- JWT_ACCESS_EXPIRATION_MINUTES=30
- JWT_REFRESH_EXPIRATION_DAYS=30
- JWT_DISCORD_REFRESH_EXPIRATION_DAY=30
- FRONTEND_URL=empty
- NOTION_API_KEY=empty
- NOTION_DATABASE_ID=empty
- LOG_LEVEL=error
- SESSION_SECRET=0%532345*edm@@u7v9+att-sdfed_l6(v*88h4$#h&o-i7awer3tv*yy
volumes:
- ./coverage:/project/coverage
depends_on:
redis:
condition: service_healthy
mongo:
condition: service_healthy
neo4j:
condition: service_healthy
rabbitmq:
condition: service_healthy
redis:
image: "redis:7.0.12-alpine"
healthcheck:
test: ["CMD", "redis-cli","ping"]
interval: 1m30s
timeout: 10s
retries: 2
start_period: 40s
mongo:
image: "mongo:5.0.10"
environment:
Expand All @@ -45,3 +78,27 @@ services:
timeout: 10s
retries: 2
start_period: 40s
rabbitmq:
image: "rabbitmq:3-management-alpine"
environment:
- RABBITMQ_DEFAULT_USER=root
- RABBITMQ_DEFAULT_PASS=pass
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 30s
timeout: 30s
retries: 2
start_period: 40s
neo4j:
image: "neo4j:5.9.0"
environment:
- NEO4J_AUTH=neo4j/password
- NEO4J_PLUGINS=["apoc", "graph-data-science"]
- NEO4J_dbms_security_procedures_unrestricted=apoc.*,gds.*
healthcheck:
test: ["CMD" ,"wget", "http://localhost:7474"]
interval: 1m30s
timeout: 10s
retries: 2
start_period: 40s

0 comments on commit 9e9f537

Please sign in to comment.