Skip to content

Commit

Permalink
[CI]: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Jan 29, 2024
1 parent bcc7216 commit c31988f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 87 deletions.
36 changes: 18 additions & 18 deletions __tests__/unit/database/services/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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]);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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',
Expand All @@ -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',
Expand Down
44 changes: 18 additions & 26 deletions __tests__/unit/database/services/guildMember.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]);
Expand Down Expand Up @@ -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);
Expand All @@ -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]);
});

Expand All @@ -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',
Expand All @@ -126,7 +125,6 @@ describe('guildMember service', () => {
updateBody,
);

console.log('MEMBER 75', await GuildMember.find({ discordId: guildMember1.discordId }))

expect(result).toMatchObject(updateBody);

Expand All @@ -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',
Expand All @@ -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);
Expand All @@ -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]);
Expand Down
42 changes: 18 additions & 24 deletions __tests__/unit/database/services/rawInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]);
Expand Down Expand Up @@ -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);
Expand All @@ -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]);
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand All @@ -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]);
Expand Down
34 changes: 16 additions & 18 deletions __tests__/unit/database/services/role.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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',
Expand All @@ -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,
Expand Down
Loading

0 comments on commit c31988f

Please sign in to comment.