Skip to content

Commit

Permalink
format: format the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Oct 24, 2024
1 parent 2c4ef7e commit 54a2072
Show file tree
Hide file tree
Showing 78 changed files with 421 additions and 1,430 deletions.
10 changes: 5 additions & 5 deletions bot/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"printWidth": 80
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"printWidth": 120
}
9 changes: 2 additions & 7 deletions bot/__tests__/fixtures/channel.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ export const channel3: IChannel = {
type: 0,
}

export const insertChannels = async function <Type>(
channels: Array<Type>,
connection: Connection
) {
await connection.models.Channel.insertMany(
channels.map((channel) => channel)
)
export const insertChannels = async function <Type>(channels: Array<Type>, connection: Connection) {
await connection.models.Channel.insertMany(channels.map((channel) => channel))
}
5 changes: 1 addition & 4 deletions bot/__tests__/fixtures/role.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export const role3: IRole = {
color: 654321,
}

export const insertRoles = async function <Type>(
roles: Array<Type>,
connection: Connection
) {
export const insertRoles = async function <Type>(roles: Array<Type>, connection: Connection) {
await connection.models.Role.insertMany(roles.map((role) => role))
}
44 changes: 8 additions & 36 deletions bot/__tests__/unit/database/services/channel.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { Connection } from 'mongoose'
import { IChannelUpdateBody, DatabaseManager } from '@togethercrew.dev/db'
import setupTestDB from '../../../utils/setupTestDB'
import {
channel1,
channel2,
channel3,
insertChannels,
} from '../../../fixtures/channel.fixture'
import { channel1, channel2, channel3, insertChannels } from '../../../fixtures/channel.fixture'
import { channelService } from '../../../../src/database/services'
setupTestDB()

describe('channel service', () => {
let connection: Connection
beforeAll(async () => {
connection =
await DatabaseManager.getInstance().getGuildDb('connection-1')
connection = await DatabaseManager.getInstance().getGuildDb('connection-1')
})
afterAll(async () => {
await connection.close()
Expand All @@ -29,10 +23,7 @@ describe('channel service', () => {
})

test('should create a channel', async () => {
const result = await channelService.createChannel(
connection,
channel1
)
const result = await channelService.createChannel(connection, channel1)
expect(result).toBeDefined()
expect(result?.channelId).toEqual(channel1.channelId)

Expand All @@ -55,10 +46,7 @@ describe('channel service', () => {
await connection.collection('channels').deleteMany({})
})
test('should create channels', async () => {
const result = await channelService.createChannels(connection, [
channel1,
channel2,
])
const result = await channelService.createChannels(connection, [channel1, channel2])
expect(result).toMatchObject([channel1, channel2])

const channelDoc1 = await channelService.getChannel(connection, {
Expand Down Expand Up @@ -137,11 +125,7 @@ describe('channel service', () => {
}
test('should update an existing channel that match the filter criteria', async () => {
await insertChannels([channel1], connection)
const result = await channelService.updateChannel(
connection,
{ channelId: channel1.channelId },
updateBody
)
const result = await channelService.updateChannel(connection, { channelId: channel1.channelId }, updateBody)
expect(result).toMatchObject(updateBody)

const channelDoc1 = await channelService.getChannel(connection, {
Expand All @@ -156,11 +140,7 @@ describe('channel service', () => {
})

test('should return null when no channel match the filter criteria', async () => {
const result = await channelService.updateChannel(
connection,
{ channelId: channel1.channelId },
updateBody
)
const result = await channelService.updateChannel(connection, { channelId: channel1.channelId }, updateBody)
expect(result).toEqual(null)
})
})
Expand All @@ -174,11 +154,7 @@ describe('channel service', () => {
}
test('should update channels that match the filter criteria', async () => {
await insertChannels([channel1, channel2, channel3], connection)
const result = await channelService.updateChannels(
connection,
{ parentId: channel2.parentId },
updateBody
)
const result = await channelService.updateChannels(connection, { parentId: channel2.parentId }, updateBody)
expect(result).toEqual(2)
const channelDoc1 = await channelService.getChannel(connection, {
channelId: channel2.channelId,
Expand All @@ -191,11 +167,7 @@ describe('channel service', () => {
})

test('should return 0 when no channels match the filter criteria', async () => {
const result = await channelService.updateChannels(
connection,
{ parentId: channel2.parentId },
updateBody
)
const result = await channelService.updateChannels(connection, { parentId: channel2.parentId }, updateBody)
expect(result).toEqual(0)
})
})
Expand Down
157 changes: 45 additions & 112 deletions bot/__tests__/unit/database/services/guildMember.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { Connection } from 'mongoose'
import { IGuildMemberUpdateBody, DatabaseManager } from '@togethercrew.dev/db'
import setupTestDB from '../../../utils/setupTestDB'
import {
guildMember1,
guildMember2,
guildMember3,
} from '../../../fixtures/guildMember.fixture'
import { guildMember1, guildMember2, guildMember3 } from '../../../fixtures/guildMember.fixture'
import { guildMemberService } from '../../../../src/database/services'
setupTestDB()

describe('guildMember service', () => {
let connection: Connection
beforeAll(async () => {
connection =
await DatabaseManager.getInstance().getGuildDb('connection-2')
connection = await DatabaseManager.getInstance().getGuildDb('connection-2')
})
afterAll(async () => {
await connection.close()
Expand All @@ -26,19 +21,13 @@ describe('guildMember service', () => {
await connection.collection('guildmembers').deleteMany({})
})
test('should create a guild member', async () => {
const result = await guildMemberService.createGuildMember(
connection,
guildMember1
)
const result = await guildMemberService.createGuildMember(connection, guildMember1)
expect(result).toBeDefined()
expect(result?.discordId).toEqual(guildMember1.discordId)

const guildMemberDoc1 = await guildMemberService.getGuildMember(
connection,
{
discordId: guildMember1.discordId,
}
)
const guildMemberDoc1 = await guildMemberService.getGuildMember(connection, {
discordId: guildMember1.discordId,
})

expect(guildMemberDoc1).toBeDefined()
expect(guildMemberDoc1).toMatchObject({
Expand All @@ -53,25 +42,16 @@ describe('guildMember service', () => {
await connection.collection('guildmembers').deleteMany({})
})
test('should create guild members', async () => {
const result = await guildMemberService.createGuildMembers(
connection,
[guildMember1, guildMember2]
)
const result = await guildMemberService.createGuildMembers(connection, [guildMember1, guildMember2])
expect(result).toMatchObject([guildMember1, guildMember2])

const guildMemberDoc1 = await guildMemberService.getGuildMember(
connection,
{
discordId: guildMember1.discordId,
}
)
const guildMemberDoc1 = await guildMemberService.getGuildMember(connection, {
discordId: guildMember1.discordId,
})

const guildMemberDoc2 = await guildMemberService.getGuildMember(
connection,
{
discordId: guildMember2.discordId,
}
)
const guildMemberDoc2 = await guildMemberService.getGuildMember(connection, {
discordId: guildMember2.discordId,
})

expect(guildMemberDoc1).toBeDefined()
expect(guildMemberDoc1).toMatchObject({
Expand Down Expand Up @@ -111,32 +91,18 @@ describe('guildMember service', () => {
await connection.collection('guildmembers').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,
}
)
await guildMemberService.createGuildMembers(connection, [guildMember1, guildMember2, guildMember3])
const result = await guildMemberService.getGuildMembers(connection, {
roles: guildMember2.roles,
})
expect(result).toMatchObject([guildMember1, guildMember2])
})

test('should return an empty array when no guild members match the filter criteria', async () => {
await guildMemberService.createGuildMembers(connection, [
guildMember1,
guildMember2,
guildMember3,
])
const result = await guildMemberService.getGuildMembers(
connection,
{
roles: ['role8'],
}
)
await guildMemberService.createGuildMembers(connection, [guildMember1, guildMember2, guildMember3])
const result = await guildMemberService.getGuildMembers(connection, {
roles: ['role8'],
})
expect(result).toEqual([])
})
})
Expand All @@ -160,12 +126,9 @@ describe('guildMember service', () => {

expect(result).toMatchObject(updateBody)

const guildMember1Doc = await guildMemberService.getGuildMember(
connection,
{
discordId: guildMember1.discordId,
}
)
const guildMember1Doc = await guildMemberService.getGuildMember(connection, {
discordId: guildMember1.discordId,
})

expect(guildMember1Doc).toBeDefined()
expect(guildMember1Doc).toMatchObject({
Expand All @@ -176,11 +139,7 @@ describe('guildMember service', () => {
})

test('should return null when no guild member match the filter criteria', async () => {
const result = await guildMemberService.updateGuildMember(
connection,
{ discordId: '1' },
updateBody
)
const result = await guildMemberService.updateGuildMember(connection, { discordId: '1' }, updateBody)
expect(result).toEqual(null)
})
})
Expand All @@ -193,29 +152,19 @@ describe('guildMember service', () => {
avatar: 'new-avatar.png',
}
test('should update guild members that match the filter criteria', async () => {
await guildMemberService.createGuildMembers(connection, [
guildMember1,
guildMember2,
guildMember3,
])
await guildMemberService.createGuildMembers(connection, [guildMember1, guildMember2, guildMember3])
const result = await guildMemberService.updateGuildMembers(
connection,
{ roles: guildMember2.roles },
updateBody
)
expect(result).toEqual(2)
const guildMember1Doc = await guildMemberService.getGuildMember(
connection,
{
discordId: guildMember1.discordId,
}
)
const guildMember2Doc = await guildMemberService.getGuildMember(
connection,
{
discordId: guildMember2.discordId,
}
)
const guildMember1Doc = await guildMemberService.getGuildMember(connection, {
discordId: guildMember1.discordId,
})
const guildMember2Doc = await guildMemberService.getGuildMember(connection, {
discordId: guildMember2.discordId,
})
expect(guildMember1Doc?.avatar).toBe(updateBody.avatar)
expect(guildMember2Doc?.avatar).toBe(updateBody.avatar)
})
Expand All @@ -236,22 +185,16 @@ describe('guildMember service', () => {
})
test('should delete guild member that match the filter criteria', async () => {
await guildMemberService.createGuildMember(connection, guildMember1)
const result = await guildMemberService.deleteGuildMember(
connection,
{
discordId: guildMember1.discordId,
}
)
const result = await guildMemberService.deleteGuildMember(connection, {
discordId: guildMember1.discordId,
})
expect(result).toEqual(true)
})

test('should return false when no guild members match the filter criteria', async () => {
const result = await guildMemberService.deleteGuildMember(
connection,
{
discordId: guildMember1.discordId,
}
)
const result = await guildMemberService.deleteGuildMember(connection, {
discordId: guildMember1.discordId,
})
expect(result).toEqual(false)
})
})
Expand All @@ -261,27 +204,17 @@ describe('guildMember service', () => {
await connection.collection('guildmembers').deleteMany({})
})
test('should delete guild members that match the filter criteria', async () => {
await guildMemberService.createGuildMembers(connection, [
guildMember1,
guildMember2,
guildMember3,
])
const result = await guildMemberService.deleteGuildMembers(
connection,
{
roles: guildMember2.roles,
}
)
await guildMemberService.createGuildMembers(connection, [guildMember1, guildMember2, guildMember3])
const result = await guildMemberService.deleteGuildMembers(connection, {
roles: guildMember2.roles,
})
expect(result).toEqual(2)
})

test('should return 0 when no guild members match the filter criteria', async () => {
const result = await guildMemberService.deleteGuildMembers(
connection,
{
roles: guildMember2.roles,
}
)
const result = await guildMemberService.deleteGuildMembers(connection, {
roles: guildMember2.roles,
})
expect(result).toEqual(0)
})
})
Expand Down
Loading

0 comments on commit 54a2072

Please sign in to comment.