diff --git a/__tests__/unit/database/services/channel.test.ts b/__tests__/unit/database/services/channel.test.ts index 58f4c893..20901518 100644 --- a/__tests__/unit/database/services/channel.test.ts +++ b/__tests__/unit/database/services/channel.test.ts @@ -7,12 +7,22 @@ import config from '../../../../src/config'; setupTestDB(); describe('channel service', () => { + let connection: Connection; + beforeAll(async () => { + connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); + }); + afterAll(async () => { + await connection.close(); + }); + beforeEach(async () => { + await connection.collection('channels').deleteMany({}); + }); + describe('createChannel', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); + test('should create a channel', async () => { const result = await channelService.createChannel(connection, channel1); expect(result).toBeDefined(); @@ -30,10 +40,8 @@ describe('channel service', () => { }); describe('createChannels', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should create channels', async () => { const result = await channelService.createChannels(connection, [channel1, channel2]); @@ -59,10 +67,8 @@ describe('channel service', () => { }); describe('getChannel', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should retrieve an existing channel that match the filter criteria', async () => { await insertChannels([channel1], connection); @@ -81,10 +87,8 @@ describe('channel service', () => { }); describe('getChannels', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should retrieve channels that match the filter criteria', async () => { await insertChannels([channel1, channel2, channel3], connection); @@ -104,10 +108,8 @@ describe('channel service', () => { }); describe('updateChannel', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); const updateBody: IChannelUpdateBody = { name: 'Channel 10', @@ -134,10 +136,8 @@ describe('channel service', () => { }); describe('updateChannels', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); const updateBody: IChannelUpdateBody = { parentId: '111111', diff --git a/__tests__/unit/database/services/guildMember.test.ts b/__tests__/unit/database/services/guildMember.test.ts index e067f9be..b222ba3f 100644 --- a/__tests__/unit/database/services/guildMember.test.ts +++ b/__tests__/unit/database/services/guildMember.test.ts @@ -7,11 +7,19 @@ import config from '../../../../src/config'; setupTestDB(); describe('guildMember service', () => { + let connection: Connection; + beforeAll(async () => { + connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); + }); + afterAll(async () => { + await connection.close(); + }); + beforeEach(async () => { + await connection.collection('guildmembers').deleteMany({}); + }); describe('createGuidMember', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should create a guild member', async () => { const result = await guildMemberService.createGuildMember(connection, guildMember1); @@ -31,10 +39,8 @@ describe('guildMember service', () => { }); describe('createGuidMembers', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should create guild members', async () => { const result = await guildMemberService.createGuildMembers(connection, [guildMember1, guildMember2]); @@ -62,10 +68,8 @@ describe('guildMember service', () => { }); describe('getGuildMember', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should retrieve an existing guild member that match the filter criteria', async () => { await guildMemberService.createGuildMember(connection, guildMember1); @@ -84,17 +88,14 @@ describe('guildMember service', () => { }); describe('getGuildMembers', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should retrieve guild members that match the filter criteria', async () => { await guildMemberService.createGuildMembers(connection, [guildMember1, guildMember2, guildMember3]); const result = await guildMemberService.getGuildMembers(connection, { roles: guildMember2.roles, }); - console.log('MEMBER 75', await GuildMember.find({})) expect(result).toMatchObject([guildMember1, guildMember2]); }); @@ -108,10 +109,8 @@ describe('guildMember service', () => { }); describe('updateGuildMember', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); const updateBody: IGuildMemberUpdateBody = { username: 'userName', @@ -126,7 +125,6 @@ describe('guildMember service', () => { updateBody, ); - console.log('MEMBER 75', await GuildMember.find({ discordId: guildMember1.discordId })) expect(result).toMatchObject(updateBody); @@ -153,10 +151,8 @@ describe('guildMember service', () => { }); describe('updateGuildMembers', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); const updateBody: IGuildMemberUpdateBody = { avatar: 'new-avatar.png', @@ -182,10 +178,8 @@ describe('guildMember service', () => { }); describe('deleteGuildMember', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should delete guild member that match the filter criteria', async () => { await guildMemberService.createGuildMember(connection, guildMember1); @@ -204,10 +198,8 @@ describe('guildMember service', () => { }); describe('deleteGuildMembers', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should delete guild members that match the filter criteria', async () => { await guildMemberService.createGuildMembers(connection, [guildMember1, guildMember2, guildMember3]); diff --git a/__tests__/unit/database/services/rawInfo.test.ts b/__tests__/unit/database/services/rawInfo.test.ts index 6efa29e0..6cc83584 100644 --- a/__tests__/unit/database/services/rawInfo.test.ts +++ b/__tests__/unit/database/services/rawInfo.test.ts @@ -7,11 +7,19 @@ import { rawInfoService } from '../../../../src/database/services'; setupTestDB(); describe('rawInfo service', () => { + let connection: Connection; + beforeAll(async () => { + connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); + }); + afterAll(async () => { + await connection.close(); + }); + beforeEach(async () => { + await connection.collection('rawinfos').deleteMany({}); + }); describe('createRawInfo', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should create a rawInfo', async () => { const result = await rawInfoService.createRawInfo(connection, rawInfo1); @@ -31,10 +39,8 @@ describe('rawInfo service', () => { }); describe('createRawInfos', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should create rawInfos (list of rawInfo)', async () => { const result = await rawInfoService.createRawInfos(connection, [rawInfo1, rawInfo2, rawInfo3]); @@ -67,10 +73,8 @@ describe('rawInfo service', () => { }); describe('getRawInfo', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should retrieve an existing rawInfo that matches the filter criteria', async () => { await rawInfoService.createRawInfo(connection, rawInfo3); @@ -90,10 +94,8 @@ describe('rawInfo service', () => { }); describe('getRawInfos', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should retrieve rawInfo that matches the filter criteria', async () => { await rawInfoService.createRawInfos(connection, [rawInfo1, rawInfo2, rawInfo3]); @@ -114,10 +116,8 @@ describe('rawInfo service', () => { }); describe('updateRawInfo', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); const updateBody: IRawInfoUpdateBody = { channelId: 'channel1', @@ -149,10 +149,8 @@ describe('rawInfo service', () => { }); describe('updateRawInfos', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); const updateBody: IRawInfoUpdateBody = { channelId: 'channel1', @@ -188,10 +186,8 @@ describe('rawInfo service', () => { }); describe('deleteRawInfo', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should delete rawInfo that matches the filter criteria', async () => { await rawInfoService.createRawInfo(connection, rawInfo1); @@ -210,10 +206,8 @@ describe('rawInfo service', () => { }); describe('deleteRawInfos', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should delete rawInfo that matches the filter criteria', async () => { await rawInfoService.createRawInfos(connection, [rawInfo1, rawInfo2, rawInfo3]); diff --git a/__tests__/unit/database/services/role.test.ts b/__tests__/unit/database/services/role.test.ts index bbfeadaf..0bb1856c 100644 --- a/__tests__/unit/database/services/role.test.ts +++ b/__tests__/unit/database/services/role.test.ts @@ -7,11 +7,19 @@ import config from '../../../../src/config'; setupTestDB(); describe('role service', () => { + let connection: Connection; + beforeAll(async () => { + connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); + }); + afterAll(async () => { + await connection.close(); + }); + beforeEach(async () => { + await connection.collection('roles').deleteMany({}); + }); describe('createRole', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should create a role', async () => { const result = await roleService.createRole(connection, role1); @@ -30,10 +38,8 @@ describe('role service', () => { }); describe('createRoles', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should create roles', async () => { const result = await roleService.createRoles(connection, [role1, role2]); @@ -59,10 +65,8 @@ describe('role service', () => { }); describe('getRole', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should retrieve an existing role that match the filter criteria', async () => { await insertRoles([role1], connection); @@ -81,10 +85,8 @@ describe('role service', () => { }); describe('getRoles', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); test('should retrieve roles that match the filter criteria', async () => { await insertRoles([role1, role2, role3], connection); @@ -104,10 +106,8 @@ describe('role service', () => { }); describe('updateRole', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); const updateBody: IRoleUpdateBody = { name: 'Role 10', @@ -134,10 +134,8 @@ describe('role service', () => { }); describe('updateRoles', () => { - let connection: Connection; beforeEach(async () => { - connection = await DatabaseManager.getInstance().getTenantDb('connection-1'); - await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({}))); + await connection.collection('channels').deleteMany({}); }); const updateBody: IRoleUpdateBody = { color: 111111, diff --git a/src/rabbitmq/events/interactionResponseCreate.ts b/src/rabbitmq/events/interactionResponseCreate.ts index bba98885..8f39884b 100644 --- a/src/rabbitmq/events/interactionResponseCreate.ts +++ b/src/rabbitmq/events/interactionResponseCreate.ts @@ -12,7 +12,6 @@ export async function handleInteractionResponseCreate(msg: any): Promise { await interactionService.createInteractionResponse(interaction, data); logger.info({ msg, event: Event.DISCORD_BOT.INTERACTION_RESPONSE.CREATE }, 'is done'); } catch (error) { - console.log(error); logger.error({ msg, event: Event.DISCORD_BOT.INTERACTION_RESPONSE.CREATE, error }, 'is failed'); } }