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 4, 2024
1 parent 38dc892 commit edace47
Show file tree
Hide file tree
Showing 122 changed files with 10,275 additions and 10,078 deletions.
23 changes: 12 additions & 11 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"env": {
"browser": true,
"es2021": true
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"rules": {}
"rules": {},
"ignorePatterns": [
"coverage",
"dist",
"__tests__/",
"jest.config.ts",
"*.yml"
]
}
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true
}
134 changes: 77 additions & 57 deletions __tests__/fixtures/announcement.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,86 @@
import { Announcement, IAnnouncement } from '@togethercrew.dev/db';
import { Types } from 'mongoose';

type AnnouncementDataFixture = Array<IAnnouncement['data'][0] & { type: string }>
type AnnouncementFixture = Pick<IAnnouncement, 'title' | 'scheduledAt' | 'draft' | 'community' | 'createdBy' | 'updatedBy'> & { _id: Types.ObjectId, data: AnnouncementDataFixture };
type AnnouncementDataFixture = Array<IAnnouncement['data'][0] & { type: string }>;
type AnnouncementFixture = Pick<
IAnnouncement,
'title' | 'scheduledAt' | 'draft' | 'community' | 'createdBy' | 'updatedBy'
> & { _id: Types.ObjectId; data: AnnouncementDataFixture };

export const generatePublicDiscordAnnouncement = (communityId: Types.ObjectId, platformId: Types.ObjectId, channelIds: string[]): AnnouncementFixture => ({
_id: new Types.ObjectId(),
title: "Announcement One",
scheduledAt: new Date(),
draft: false,
community: communityId,
data: [{
platform: platformId,
type: "discord_public",
template: "Hello World",
options: {
channelIds: channelIds,
},
}],
createdBy: new Types.ObjectId(),
updatedBy: new Types.ObjectId(),
export const generatePublicDiscordAnnouncement = (
communityId: Types.ObjectId,
platformId: Types.ObjectId,
channelIds: string[],
): AnnouncementFixture => ({
_id: new Types.ObjectId(),
title: 'Announcement One',
scheduledAt: new Date(),
draft: false,
community: communityId,
data: [
{
platform: platformId,
type: 'discord_public',
template: 'Hello World',
options: {
channelIds: channelIds,
},
},
],
createdBy: new Types.ObjectId(),
updatedBy: new Types.ObjectId(),
});

export const generatePrivateUserDiscordAnnouncement = (communityId: Types.ObjectId, platformId: Types.ObjectId, userIds: any[]): AnnouncementFixture => ({
_id: new Types.ObjectId(),
title: "Announcement Two",
scheduledAt: new Date(),
draft: false,
community: communityId,
data: [{
platform: platformId,
type: "discord_private",
template: "Hello api world",
options: {
userIds: userIds,
},
}],
createdBy: new Types.ObjectId(),
updatedBy: new Types.ObjectId(),
})
export const generatePrivateUserDiscordAnnouncement = (
communityId: Types.ObjectId,
platformId: Types.ObjectId,
userIds: any[],
): AnnouncementFixture => ({
_id: new Types.ObjectId(),
title: 'Announcement Two',
scheduledAt: new Date(),
draft: false,
community: communityId,
data: [
{
platform: platformId,
type: 'discord_private',
template: 'Hello api world',
options: {
userIds: userIds,
},
},
],
createdBy: new Types.ObjectId(),
updatedBy: new Types.ObjectId(),
});

export const generatePrivateRoleDiscordAnnouncement = (communityId: Types.ObjectId, platformId: Types.ObjectId, roleIds: any[]): AnnouncementFixture => ({
_id: new Types.ObjectId(),
title: "Announcement Three",
scheduledAt: new Date(),
draft: false,
community: communityId,
data: [{
platform: platformId,
type: "discord_private",
template: "Sample Template",
options: {
roleIds: roleIds,
},
}],
createdBy: new Types.ObjectId(),
updatedBy: new Types.ObjectId(),
})
export const generatePrivateRoleDiscordAnnouncement = (
communityId: Types.ObjectId,
platformId: Types.ObjectId,
roleIds: any[],
): AnnouncementFixture => ({
_id: new Types.ObjectId(),
title: 'Announcement Three',
scheduledAt: new Date(),
draft: false,
community: communityId,
data: [
{
platform: platformId,
type: 'discord_private',
template: 'Sample Template',
options: {
roleIds: roleIds,
},
},
],
createdBy: new Types.ObjectId(),
updatedBy: new Types.ObjectId(),
});

export const insertAnnouncement = async (announcements: AnnouncementFixture[]) => {
for (const announcement of announcements) {
await Announcement.create(announcement);
}
}

for (const announcement of announcements) {
await Announcement.create(announcement);
}
};
33 changes: 16 additions & 17 deletions __tests__/fixtures/community.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@ import { Types } from 'mongoose';
import { Community } from '@togethercrew.dev/db';

interface CommunityFixture {
_id: Types.ObjectId;
name: string;
avatarURL?: string;
users?: Types.ObjectId[];
platforms?: Types.ObjectId[];
_id: Types.ObjectId;
name: string;
avatarURL?: string;
users?: Types.ObjectId[];
platforms?: Types.ObjectId[];
}


export const communityOne: CommunityFixture = {
_id: new Types.ObjectId(),
name: "Community Alpha",
avatarURL: "path/to/avatar1.png",
_id: new Types.ObjectId(),
name: 'Community Alpha',
avatarURL: 'path/to/avatar1.png',
};

export const communityTwo: CommunityFixture = {
_id: new Types.ObjectId(),
name: "Community Beta",
_id: new Types.ObjectId(),
name: 'Community Beta',
};

export const communityThree: CommunityFixture = {
_id: new Types.ObjectId(),
name: "Community Teta",
_id: new Types.ObjectId(),
name: 'Community Teta',
};

export const insertCommunities = async function <Type>(communities: Array<Type>) {
for (const community of communities) {
await Community.create(community);
}
};
for (const community of communities) {
await Community.create(community);
}
};
122 changes: 60 additions & 62 deletions __tests__/fixtures/discord/channels.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,78 @@ import { IChannel } from '@togethercrew.dev/db';
import { Connection } from 'mongoose';

export const discordChannel1: IChannel = {
channelId: '987654321098765432',
name: 'Channel 1',
parentId: null,
permissionOverwrites: [

{
id: '9988776655', // another example Snowflake ID for the role or member
type: 1,
allow: '1000',
deny: '0',
},
],
deletedAt: null
channelId: '987654321098765432',
name: 'Channel 1',
parentId: null,
permissionOverwrites: [
{
id: '9988776655', // another example Snowflake ID for the role or member
type: 1,
allow: '1000',
deny: '0',
},
],
deletedAt: null,
};

export const discordChannel2: IChannel = {
channelId: '234567890123456789',
name: 'Channel 2',
parentId: '987654321098765432',
permissionOverwrites: [
{
id: '1130918826234617968', // example Snowflake ID for the role or member
type: 1,
allow: '0',
deny: '66560',
},
{
id: '9988776655', // another example Snowflake ID for the role or member
type: 1,
allow: '10000',
deny: '0',
},
],
deletedAt: null
channelId: '234567890123456789',
name: 'Channel 2',
parentId: '987654321098765432',
permissionOverwrites: [
{
id: '1130918826234617968', // example Snowflake ID for the role or member
type: 1,
allow: '0',
deny: '66560',
},
{
id: '9988776655', // another example Snowflake ID for the role or member
type: 1,
allow: '10000',
deny: '0',
},
],
deletedAt: null,
};

export const discordChannel3: IChannel = {
channelId: '345678901234567890',
name: 'Channel 3',
parentId: '987654321098765432',
permissionOverwrites: [
{
id: '9988776655', // another example Snowflake ID for the role or member
type: 1,
allow: '10000',
deny: '0',
},
{
id: '1130918826234617968', // example Snowflake ID for the role or member
type: 1,
allow: '66560',
deny: '0',
},
],
deletedAt: null
channelId: '345678901234567890',
name: 'Channel 3',
parentId: '987654321098765432',
permissionOverwrites: [
{
id: '9988776655', // another example Snowflake ID for the role or member
type: 1,
allow: '10000',
deny: '0',
},
{
id: '1130918826234617968', // example Snowflake ID for the role or member
type: 1,
allow: '66560',
deny: '0',
},
],
deletedAt: null,
};

export const discordChannel4: IChannel = {
channelId: '345678901234567000',
name: 'Channel 4',
parentId: null,
deletedAt: null
channelId: '345678901234567000',
name: 'Channel 4',
parentId: null,
deletedAt: null,
};

export const discordChannel5: IChannel = {
channelId: '345678901234567333',
name: 'Channel 5',
parentId: '987654321098765432',
deletedAt: new Date()
channelId: '345678901234567333',
name: 'Channel 5',
parentId: '987654321098765432',
deletedAt: new Date(),
};


export const insertChannels = async function <Type>(channels: Array<Type>, connection: Connection) {
for (const channel of channels) {
await connection.models.Channel.create(channel);
}
};
for (const channel of channels) {
await connection.models.Channel.create(channel);
}
};
Loading

0 comments on commit edace47

Please sign in to comment.