Skip to content

Commit

Permalink
Merge pull request #334 from TogetherCrew/upv1
Browse files Browse the repository at this point in the history
User Permission V1
  • Loading branch information
Behzad-rabiei authored Apr 4, 2024
2 parents bb8d653 + 60ff54e commit 68f517f
Show file tree
Hide file tree
Showing 44 changed files with 1,015 additions and 311 deletions.
34 changes: 33 additions & 1 deletion __tests__/fixtures/community.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,60 @@
import { Types } from 'mongoose';
import { Community } from '@togethercrew.dev/db';
import { Community, ICommunityRoles } from '@togethercrew.dev/db';

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

export const communityOne: CommunityFixture = {
_id: new Types.ObjectId(),
name: 'Community Alpha',
avatarURL: 'path/to/avatar1.png',
roles: [
{
roleType: 'admin',
source: {
platform: 'discord',
identifierType: 'member',
identifierValues: ['987654321'],
platformId: new Types.ObjectId(),
},
},
{
roleType: 'view',
source: {
platform: 'discord',
identifierType: 'member',
identifierValues: ['987654321'],
platformId: new Types.ObjectId(),
},
},
{
roleType: 'admin',
source: {
platform: 'discord',
identifierType: 'role',
identifierValues: ['652345789987654321'],
platformId: new Types.ObjectId(),
},
},
],
};

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

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

export const insertCommunities = async function <Type>(communities: Array<Type>) {
Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/platform.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const platformThree: PlatformFixture = {
metadata: {
id: '681946187490000802',
},
disconnectedAt: null,
};

export const platformFour: PlatformFixture = {
Expand Down
8 changes: 7 additions & 1 deletion __tests__/fixtures/token.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import moment from 'moment';
import config from '../../src/config';
import { tokenTypes } from '../../src/config/tokens';
import { tokenService } from '../../src/services';
import { userOne, userTwo } from './user.fixture';
import { userOne, userTwo, userThree } from './user.fixture';

const accessTokenExpires = moment().add(config.jwt.accessExpirationMinutes, 'minutes');
export const userOneAccessToken = tokenService.generateToken(
Expand All @@ -15,3 +15,9 @@ export const userTwoAccessToken = tokenService.generateToken(
accessTokenExpires,
tokenTypes.ACCESS,
);

export const userThreeAccessToken = tokenService.generateToken(
{ ...userThree, id: userThree._id },
accessTokenExpires,
tokenTypes.ACCESS,
);
6 changes: 3 additions & 3 deletions __tests__/fixtures/user.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ interface UserFixture {

export const userOne: UserFixture = {
_id: new Types.ObjectId(),
discordId: crypto.randomBytes(20).toString('hex'),
discordId: '123456789',
email: '[email protected]',
};

export const userTwo: UserFixture = {
_id: new Types.ObjectId(),
discordId: crypto.randomBytes(20).toString('hex'),
discordId: '987654321',
};

export const userThree: UserFixture = {
_id: new Types.ObjectId(),
discordId: crypto.randomBytes(20).toString('hex'),
discordId: '555555555',
};

export const insertUsers = async function <Type>(users: Array<Type>) {
Expand Down
7 changes: 1 addition & 6 deletions __tests__/integration/announcement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
// import { DatabaseManager } from '@togethercrew.dev/db';
// import { insertPlatforms, platformOne } from '../fixtures/platform.fixture';
// import { discordGuildMember1, discordGuildMember2, insertGuildMembers } from '../fixtures/discord/guildMember.fixture';
// import platform from '../../src/middlewares/platform';

// setupTestDB();

// describe('Community routes', () => {
// describe('Announcement routes', () => {
// const announcementOne = generatePublicDiscordAnnouncement(communityOne._id, platformOne._id, [
// discordChannel4.channelId,
// discordChannel3.channelId,
Expand All @@ -40,10 +39,6 @@
// connection = await DatabaseManager.getInstance().getTenantDb(platformOne.metadata?.id);
// });

// afterAll(async () => {
// await connection.close();
// });

// beforeEach(async () => {
// cleanUpTenantDatabases();
// userOne.communities = [communityOne._id, communityTwo._id];
Expand Down
Loading

0 comments on commit 68f517f

Please sign in to comment.