Skip to content

Commit

Permalink
format the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Mar 6, 2024
1 parent d5eb5cb commit 3a74e68
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 38 deletions.
26 changes: 1 addition & 25 deletions __tests__/integration/community.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import request from 'supertest';
import httpStatus from 'http-status';
import app from '../../src/app';
import setupTestDB, { cleanUpTenantDatabases } from '../utils/setupTestDB';
import setupTestDB from '../utils/setupTestDB';
import { userOne, insertUsers, userTwo } from '../fixtures/user.fixture';
import { userOneAccessToken } from '../fixtures/token.fixture';
import { User, Community, ICommunityUpdateBody } from '@togethercrew.dev/db';
import { communityOne, communityTwo, communityThree, insertCommunities } from '../fixtures/community.fixture';
import { DatabaseManager } from '@togethercrew.dev/db';
import { platformOne, platformTwo, platformFour, insertPlatforms } from '../fixtures/platform.fixture';
import { Connection } from 'mongoose';

setupTestDB();

describe('Community routes', () => {
let connection: Connection;
beforeAll(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
});
afterAll(async () => {
await connection.close();
});
beforeEach(() => {
cleanUpTenantDatabases();
userOne.communities = [communityOne._id, communityTwo._id];
userTwo.communities = [communityThree._id];
communityOne.users = [userOne._id];
Expand All @@ -35,7 +24,6 @@ describe('Community routes', () => {
const currentDate = new Date();

beforeEach(() => {
cleanUpTenantDatabases();
newCommunity = {
name: 'Community A',
avatarURL: 'path',
Expand Down Expand Up @@ -108,9 +96,6 @@ describe('Community routes', () => {
});

describe('GET /api/v1/communities', () => {
beforeEach(async () => {
cleanUpTenantDatabases();
});
test('should return 200 and apply the default query options', async () => {
await insertCommunities([communityOne, communityTwo, communityThree]);
await insertUsers([userOne, userTwo]);
Expand Down Expand Up @@ -265,9 +250,6 @@ describe('Community routes', () => {
});

describe('GET /api/v1/communities/:communityId', () => {
beforeEach(async () => {
cleanUpTenantDatabases();
});
test('should return 200 and the community object if data is ok', async () => {
await insertCommunities([communityOne, communityTwo, communityThree]);
await insertUsers([userOne, userTwo]);
Expand Down Expand Up @@ -323,9 +305,6 @@ describe('Community routes', () => {
});

describe('PATCH /api/v1/communities/:communityId', () => {
beforeEach(async () => {
cleanUpTenantDatabases();
});
let updateBody: ICommunityUpdateBody;
const currentDate = new Date();

Expand Down Expand Up @@ -418,9 +397,6 @@ describe('Community routes', () => {
});
});
describe('DELETE /api/v1/communities/:communityId', () => {
beforeEach(async () => {
cleanUpTenantDatabases();
});
test('should return 204 if data is ok', async () => {
await insertCommunities([communityOne, communityTwo, communityThree]);
await insertUsers([userOne, userTwo]);
Expand Down
33 changes: 20 additions & 13 deletions __tests__/integration/platform.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import request from 'supertest';
import httpStatus from 'http-status';
import app from '../../src/app';
import setupTestDB from '../utils/setupTestDB';
import setupTestDB, { cleanUpTenantDatabases } from '../utils/setupTestDB';
import { userOne, insertUsers, userTwo } from '../fixtures/user.fixture';
import { userOneAccessToken } from '../fixtures/token.fixture';
import { Platform, Community, IPlatformUpdateBody, DatabaseManager } from '@togethercrew.dev/db';
Expand Down Expand Up @@ -40,16 +40,13 @@ setupTestDB();
describe('Platform routes', () => {
let connection: Connection;
beforeAll(async () => {
connection = await DatabaseManager.getInstance().getTenantDb('connection-platform');
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
});
afterAll(async () => {
await connection.close();
});
beforeEach(async () => {
await Promise.all(
Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({})),
);
await Promise.all(Object.values(connection.collections).map(async (collection) => collection.deleteMany({})));
cleanUpTenantDatabases();
userOne.communities = [communityOne._id, communityTwo._id];
userTwo.communities = [communityThree._id];

Expand All @@ -68,6 +65,9 @@ describe('Platform routes', () => {
platformFive.community = communityOne._id;
});
describe('POST api/v1/platforms', () => {
beforeEach(async () => {
cleanUpTenantDatabases();
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let newPlatform: any;

Expand Down Expand Up @@ -245,6 +245,9 @@ describe('Platform routes', () => {
});
});
describe('GET /api/v1/platforms', () => {
beforeEach(async () => {
cleanUpTenantDatabases();
});
test('should return 200 and apply the default query options', async () => {
await insertCommunities([communityOne, communityTwo, communityThree]);
await insertUsers([userOne, userTwo]);
Expand Down Expand Up @@ -401,6 +404,9 @@ describe('Platform routes', () => {
});
});
describe('GET /api/v1/platforms/:platformId', () => {
beforeEach(async () => {
cleanUpTenantDatabases();
});
discordServices.coreService.getBotPermissions = jest.fn().mockReturnValue(['ViewChannel', 'ReadMessageHistory']);
test('should return 200 and the platform object if data is ok', async () => {
await insertCommunities([communityOne, communityTwo, communityThree]);
Expand Down Expand Up @@ -479,6 +485,9 @@ describe('Platform routes', () => {
});
});
describe('PATCH /api/v1/platforms/:platformId', () => {
beforeEach(async () => {
cleanUpTenantDatabases();
});
let updateBody: IPlatformUpdateBody;

beforeEach(() => {
Expand Down Expand Up @@ -629,6 +638,9 @@ describe('Platform routes', () => {
});
});
describe('DELETE /api/v1/platforms/:platformId', () => {
beforeEach(async () => {
cleanUpTenantDatabases();
});
discordServices.coreService.leaveBotFromGuild = jest.fn().mockReturnValue(null);
test('should return 204 and soft delete the platform is deleteType is soft', async () => {
await insertCommunities([communityOne, communityTwo, communityThree]);
Expand Down Expand Up @@ -702,15 +714,10 @@ describe('Platform routes', () => {
});
});
describe('POST /:platformId/properties', () => {
discordServices.coreService.getBotPermissions = jest.fn().mockReturnValue(['ViewChannel', 'ReadMessageHistory']);
let connection: Connection;
beforeAll(async () => {
connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
});
beforeEach(async () => {
await connection.dropDatabase();
cleanUpTenantDatabases();
});

discordServices.coreService.getBotPermissions = jest.fn().mockReturnValue(['ViewChannel', 'ReadMessageHistory']);
test('should return 200 and apply the default query options if requested property is discord-role', async () => {
await insertCommunities([communityOne]);
await insertUsers([userOne]);
Expand Down

0 comments on commit 3a74e68

Please sign in to comment.