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 Apr 10, 2024
1 parent bc9e55d commit 6f3b6f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 82 deletions.
65 changes: 0 additions & 65 deletions __tests__/unit/models/platform.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,70 +23,5 @@ describe('Platform model', () => {
test('should correctly validate a valid platform', async () => {
await expect(new Platform(platform).validate()).resolves.toBeUndefined();
});

// describe('Middlewares', () => {
// test('Pre Remove: should clean up when platform is deleted', async () => {
// const user = new User({ discordId: 'discordId' });
// await user.save();

// const community = new Community({ users: [user._id], name: 'community' });
// await community.save();

// const platform = new Platform({ name: 'platform', community: community._id });
// await platform.save();

// const module = new Module({
// name: 'hivemind',
// community: community._id,
// options: { platforms: [{ platform: platform._id }, { platform: new Types.ObjectId() }] },
// });
// await module.save();

// let communityDoc = await Community.findById(community.id);
// if (communityDoc?.platforms) {
// const idAsString = platform.id.toHexString ? platform.id.toHexString() : platform.id;
// expect(communityDoc.platforms[0].toHexString()).toBe(idAsString);
// }
// await platform.remove();
// communityDoc = await Community.findById(community.id);
// expect(communityDoc?.platforms).toEqual([]);
// expect(communityDoc?.roles).toEqual([]);

// const platformDoc = await Platform.findById(platform._id);
// expect(platformDoc).toBe(null);

// const moduleDoc = await Module.findById(module._id);
// expect(moduleDoc?.options?.platforms.length).toBe(1);
// });

// test('Post Save: should add platformId to the community and admin role for the creator of community', async () => {
// const user = new User({ discordId: 'discordId' });
// await user.save();

// const community = new Community({ users: [user._id], name: 'community' });
// await community.save();
// user.communities?.push(community._id);

// const platform = new Platform({ name: 'platform', community: community._id });
// await platform.save();
// const communityDoc = await Community.findById(community.id);
// if (communityDoc?.platforms && communityDoc?.roles) {
// const idAsString = platform.id.toHexString ? platform.id.toHexString() : platform.id;
// expect(communityDoc.platforms[0].toHexString()).toBe(idAsString);
// expect(JSON.parse(JSON.stringify(communityDoc.roles))).toEqual([
// {
// _id: expect.anything(),
// roleType: 'admin',
// source: {
// platform: 'discord',
// identifierType: 'member',
// identifierValues: [user.discordId],
// platformId: platform._id.toHexString(),
// },
// },
// ]);
// }
// });
// });
});
});
34 changes: 17 additions & 17 deletions __tests__/utils/setupTestDB.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import mongoose from 'mongoose';
import config from '../../src/config';
// import mongoose from 'mongoose';
// import config from '../../src/config';

const setupTestDB = () => {
beforeAll(async () => {
mongoose.set('strictQuery', false);
await mongoose.connect(config.mongoose.serverURL);
});
// const setupTestDB = () => {
// beforeAll(async () => {
// mongoose.set('strictQuery', false);
// await mongoose.connect(config.mongoose.serverURL);
// });

beforeEach(async () => {
await Promise.all(
Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({})),
);
});
// beforeEach(async () => {
// await Promise.all(
// Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany({})),
// );
// });

afterAll(async () => {
await mongoose.disconnect();
});
};
// afterAll(async () => {
// await mongoose.disconnect();
// });
// };

export default setupTestDB;
// export default setupTestDB;

0 comments on commit 6f3b6f7

Please sign in to comment.