Skip to content

Conversation

@Behzad-rabiei
Copy link
Member

@Behzad-rabiei Behzad-rabiei commented May 14, 2024

Summary by CodeRabbit

  • New Features

    • Added support for new platforms: Notion and MediaWiki.
    • Enhanced metadata descriptions for MediaWiki and Notion platforms.
  • Bug Fixes

    • Improved validation for platform and module names to ensure data integrity.
  • Refactor

    • Centralized token type and platform name definitions for better maintainability and consistency.
    • Updated import statements to use centralized enums for platform and token names.
  • Documentation

    • Updated API documentation to reflect new platform support and metadata descriptions.

@coderabbitai
Copy link

coderabbitai bot commented May 14, 2024

Walkthrough

The updates primarily involve refactoring the codebase to use centralized enums for token types and platform names from the @togethercrew.dev/db module instead of local definitions. This change enhances consistency and maintainability across various components, including tests, services, controllers, and documentation. Additionally, new platform support for Notion and MediaWiki has been integrated, with corresponding validation and metadata handling.

Changes

Files/Paths Change Summaries
__tests__/fixtures/token.fixture.ts, src/config/passport.ts, src/services/token.service.ts Updated to use TokenTypeNames from @togethercrew.dev/db instead of local token definitions.
__tests__/integration/module.test.ts, src/controllers/platform.controller.ts, src/services/platform.service.ts, src/validations/module.validation.ts, src/validations/platform.validation.ts Replaced string literals with enums (PlatformNames, ModuleNames) for platform and module names.
__tests__/integration/platform.test.ts Added a test case for creating a new mediaWiki platform.
package.json Updated the version of @togethercrew.dev/db from ^3.0.55 to ^3.0.60.
src/docs/module.doc.yml, src/docs/platform.doc.yml Expanded platform support to include Notion and MediaWiki, with updates to descriptions and parameters.
src/services/auth.service.ts Updated to use TokenTypeNames for token type comparisons.
src/validations/community.validation.ts Updated validation schema to use PlatformNames.Discord instead of a string literal.

🐰

In code we trust, enums we bring,
Consistency now reigns, a unified string.
Platforms and tokens, all in a row,
Notion and MediaWiki, watch them grow.
Together we build, with enums so bright,
A future of code, shining in the light.

🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between ddefd69 and 7703806.
Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (14)
  • tests/fixtures/token.fixture.ts (1 hunks)
  • tests/integration/module.test.ts (8 hunks)
  • tests/integration/platform.test.ts (1 hunks)
  • package.json (1 hunks)
  • src/config/passport.ts (2 hunks)
  • src/controllers/platform.controller.ts (17 hunks)
  • src/docs/module.doc.yml (2 hunks)
  • src/docs/platform.doc.yml (4 hunks)
  • src/services/auth.service.ts (3 hunks)
  • src/services/platform.service.ts (3 hunks)
  • src/services/token.service.ts (6 hunks)
  • src/validations/community.validation.ts (2 hunks)
  • src/validations/module.validation.ts (3 hunks)
  • src/validations/platform.validation.ts (5 hunks)
Files skipped from review due to trivial changes (1)
  • package.json
Additional comments not posted (58)
__tests__/fixtures/token.fixture.ts (4)

3-3: LGTM! The import of TokenTypeNames from @togethercrew.dev/db enhances consistency.


11-11: LGTM! The use of TokenTypeNames.ACCESS improves maintainability.


16-16: LGTM! The use of TokenTypeNames.ACCESS improves maintainability.


22-22: LGTM! The use of TokenTypeNames.ACCESS improves maintainability.

src/config/passport.ts (2)

3-3: LGTM! The import of TokenTypeNames from @togethercrew.dev/db enhances consistency.


19-19: LGTM! The use of TokenTypeNames.ACCESS improves maintainability.

src/validations/community.validation.ts (2)

3-3: LGTM! The import of PlatformNames from @togethercrew.dev/db enhances consistency.


43-43: LGTM! The use of PlatformNames.Discord improves maintainability.

src/validations/module.validation.ts (7)

1-1: LGTM! The import of PlatformNames, ModuleNames, and HivemindPlatformNames from @togethercrew.dev/db enhances consistency.


7-9: LGTM! The use of ModuleNames improves maintainability.


16-16: LGTM! The use of ModuleNames improves maintainability.


69-73: LGTM! The addition of hivemindMediaWikiMetadata improves functionality.


79-81: LGTM! The use of HivemindPlatformNames improves maintainability.


86-104: LGTM! The use of PlatformNames improves maintainability.


123-123: LGTM! The use of ModuleNames.Hivemind improves maintainability.

src/services/auth.service.ts (3)

7-7: LGTM! The import of TokenTypeNames from @togethercrew.dev/db enhances consistency.


91-94: LGTM! The use of TokenTypeNames.REFRESH improves maintainability.


108-108: LGTM! The use of TokenTypeNames.REFRESH improves maintainability.

src/services/token.service.ts (9)

6-6: LGTM! The import of TokenTypeNames from @togethercrew.dev/db enhances consistency.


79-79: LGTM! The use of TokenTypeNames.ACCESS improves maintainability.


82-83: LGTM! The use of TokenTypeNames.REFRESH improves maintainability.


110-110: LGTM! The use of TokenTypeNames.DISCORD_ACCESS improves maintainability.


116-116: LGTM! The use of TokenTypeNames.DISCORD_REFRESH improves maintainability.


141-141: LGTM! The use of TokenTypeNames.GOOGLE_ACCESS improves maintainability.


144-144: LGTM! The use of TokenTypeNames.GOOGLE_REFRESH improves maintainability.


156-157: LGTM! The use of TokenTypeNames.DISCORD_ACCESS and TokenTypeNames.DISCORD_REFRESH improves maintainability.


187-187: LGTM! The use of TokenTypeNames.NOTION_ACCESS improves maintainability.

src/validations/platform.validation.ts (11)

2-2: LGTM! The import of PlatformNames from @togethercrew.dev/db enhances consistency.


6-6: LGTM! The import of PlatformNames from @togethercrew.dev/db enhances consistency.


70-74: LGTM! The addition of mediaWikiMetadata improves functionality.


78-80: LGTM! The use of PlatformNames improves maintainability.


85-107: LGTM! The use of PlatformNames improves maintainability.


115-117: LGTM! The use of PlatformNames improves maintainability.


121-121: LGTM! The use of PlatformNames improves maintainability.


126-126: LGTM! The use of PlatformNames improves maintainability.


135-135: LGTM! The use of PlatformNames improves maintainability.


163-163: LGTM! The use of PlatformNames improves maintainability.


241-244: LGTM! The use of PlatformNames.Discord improves maintainability.

src/services/platform.service.ts (3)

8-9: LGTM! The import of PlatformNames from @togethercrew.dev/db enhances consistency.


Line range hint 16-26: LGTM! The use of PlatformNames.Discord improves maintainability.


143-152: LGTM! The use of PlatformNames improves maintainability.

src/docs/module.doc.yml (2)

168-168: Add new platform names to the enum list.

The new platform names 'notion' and 'mediaWiki' have been correctly added to the enum list.


230-236: Add metadata descriptions for the new platform 'MediaWiki'.

The metadata descriptions for 'MediaWiki' have been correctly added and are consistent with the rest of the metadata descriptions.

src/controllers/platform.controller.ts (10)

20-20: Import PlatformNames from @togethercrew.dev/db.

The import statement for PlatformNames has been correctly added.


34-34: Replace string literal 'discord' with PlatformNames.Discord.

The string literal 'discord' has been correctly replaced with PlatformNames.Discord.


45-45: Replace string literal 'twitter' with PlatformNames.Twitter.

The string literal 'twitter' has been correctly replaced with PlatformNames.Twitter.


50-50: Replace string literal 'google' with PlatformNames.Google.

The string literal 'google' has been correctly replaced with PlatformNames.Google.


67-67: Replace string literal 'github' with PlatformNames.GitHub.

The string literal 'github' has been correctly replaced with PlatformNames.GitHub.


70-70: Replace string literal 'notion' with PlatformNames.Notion.

The string literal 'notion' has been correctly replaced with PlatformNames.Notion.


94-94: Replace string literal 'discord' with PlatformNames.Discord in the connectDiscordCallback function.

The string literal 'discord' has been correctly replaced with PlatformNames.Discord in the connectDiscordCallback function.


130-130: Replace string literal 'twitter' with PlatformNames.Twitter in the connectTwitterCallback function.

The string literal 'twitter' has been correctly replaced with PlatformNames.Twitter in the connectTwitterCallback function.


172-172: Replace string literal 'google' with PlatformNames.Google in the connectGoogleCallback function.

The string literal 'google' has been correctly replaced with PlatformNames.Google in the connectGoogleCallback function.


208-208: Replace string literal 'github' with PlatformNames.GitHub in the connectGithubCallback function.

The string literal 'github' has been correctly replaced with PlatformNames.GitHub in the connectGithubCallback function.

src/docs/platform.doc.yml (3)

7-7: Update description to include 'Notion' and 'MediaWiki'.

The description has been correctly updated to include 'Notion' and 'MediaWiki'.


69-69: Add 'mediaWiki' to the enum list for platform creation.

The new platform name 'mediaWiki' has been correctly added to the enum list for platform creation.


201-201: Add 'mediaWiki' to the enum list for platform retrieval.

The new platform name 'mediaWiki' has been correctly added to the enum list for platform retrieval.

__tests__/integration/module.test.ts (2)

81-82: LGTM! The usage of ModuleNames.Hivemind is correct.


389-389: LGTM! The usage of PlatformNames.Discord is correct.

// import { analyzerAction, analyzerWindow } from '../../src/config/analyzer.statics';
// import { Connection, Types } from 'mongoose';
// import mongoose from 'mongoose';
// import { ModuleNames, PlatformNames } from '@togethercrew.dev/db';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment the import statement for PlatformNames.

- // import { ModuleNames, PlatformNames } from '@togethercrew.dev/db';
+ import { ModuleNames, PlatformNames } from '@togethercrew.dev/db';

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// import { ModuleNames, PlatformNames } from '@togethercrew.dev/db';
import { ModuleNames, PlatformNames } from '@togethercrew.dev/db';

Comment on lines +274 to +315
// test('should return 201 and successfully create new mediaWiki platform if data is ok', async () => {
// userOne.communities = [communityOne._id];
// communityOne.users = [userOne._id];
// await insertCommunities([communityOne]);
// await insertUsers([userOne]);
// newPlatform = {
// name: 'mediaWiki',
// community: communityOne._id,
// metadata: {
// baseURL: 'base',
// },
// };
// const res = await request(app)
// .post(`/api/v1/platforms`)
// .set('Authorization', `Bearer ${userOneAccessToken}`)
// .send(newPlatform)
// .expect(httpStatus.CREATED);

// expect(res.body).toEqual({
// id: expect.anything(),
// name: newPlatform.name,
// metadata: newPlatform.metadata,
// community: communityOne._id.toHexString(),
// disconnectedAt: null,
// connectedAt: expect.anything(),
// });

// const dbPlatform = await Platform.findById(res.body.id);
// expect(dbPlatform).toBeDefined();
// expect(dbPlatform).toMatchObject({
// name: newPlatform.name,
// metadata: newPlatform.metadata,
// });

// const dbCommunity = await Community.findById(res.body.community);
// expect(dbCommunity).toMatchObject({
// id: communityOne._id.toHexString(),
// name: communityOne.name,
// avatarURL: communityOne.avatarURL,
// users: [userOne._id],
// });
// });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment the test case for creating a mediaWiki platform.

The test case for creating a mediaWiki platform is commented out. Uncomment the test case to ensure it is executed and validated.

- //     test('should return 201 and successfully create new mediaWiki platform if data is ok', async () => {
- //       userOne.communities = [communityOne._id];
- //       communityOne.users = [userOne._id];
- //       await insertCommunities([communityOne]);
- //       await insertUsers([userOne]);
- //       newPlatform = {
- //         name: 'mediaWiki',
- //         community: communityOne._id,
- //         metadata: {
- //           baseURL: 'base',
- //         },
- //       };
- //       const res = await request(app)
- //         .post(`/api/v1/platforms`)
- //         .set('Authorization', `Bearer ${userOneAccessToken}`)
- //         .send(newPlatform)
- //         .expect(httpStatus.CREATED);
- //
- //       expect(res.body).toEqual({
- //         id: expect.anything(),
- //         name: newPlatform.name,
- //         metadata: newPlatform.metadata,
- //         community: communityOne._id.toHexString(),
- //         disconnectedAt: null,
- //         connectedAt: expect.anything(),
- //       });
- //
- //       const dbPlatform = await Platform.findById(res.body.id);
- //       expect(dbPlatform).toBeDefined();
- //       expect(dbPlatform).toMatchObject({
- //         name: newPlatform.name,
- //         metadata: newPlatform.metadata,
- //       });
- //
- //       const dbCommunity = await Community.findById(res.body.community);
- //       expect(dbCommunity).toMatchObject({
- //         id: communityOne._id.toHexString(),
- //         name: communityOne.name,
- //         avatarURL: communityOne.avatarURL,
- //         users: [userOne._id],
- //       });
- //     });
+     test('should return 201 and successfully create new mediaWiki platform if data is ok', async () => {
+       userOne.communities = [communityOne._id];
+       communityOne.users = [userOne._id];
+       await insertCommunities([communityOne]);
+       await insertUsers([userOne]);
+       newPlatform = {
+         name: 'mediaWiki',
+         community: communityOne._id,
+         metadata: {
+           baseURL: 'base',
+         },
+       };
+       const res = await request(app)
+         .post(`/api/v1/platforms`)
+         .set('Authorization', `Bearer ${userOneAccessToken}`)
+         .send(newPlatform)
+         .expect(httpStatus.CREATED);
+
+       expect(res.body).toEqual({
+         id: expect.anything(),
+         name: newPlatform.name,
+         metadata: newPlatform.metadata,
+         community: communityOne._id.toHexString(),
+         disconnectedAt: null,
+         connectedAt: expect.anything(),
+       });
+
+       const dbPlatform = await Platform.findById(res.body.id);
+       expect(dbPlatform).toBeDefined();
+       expect(dbPlatform).toMatchObject({
+         name: newPlatform.name,
+         metadata: newPlatform.metadata,
+       });
+
+       const dbCommunity = await Community.findById(res.body.community);
+       expect(dbCommunity).toMatchObject({
+         id: communityOne._id.toHexString(),
+         name: communityOne.name,
+         avatarURL: communityOne.avatarURL,
+         users: [userOne._id],
+       });
+     });

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// test('should return 201 and successfully create new mediaWiki platform if data is ok', async () => {
// userOne.communities = [communityOne._id];
// communityOne.users = [userOne._id];
// await insertCommunities([communityOne]);
// await insertUsers([userOne]);
// newPlatform = {
// name: 'mediaWiki',
// community: communityOne._id,
// metadata: {
// baseURL: 'base',
// },
// };
// const res = await request(app)
// .post(`/api/v1/platforms`)
// .set('Authorization', `Bearer ${userOneAccessToken}`)
// .send(newPlatform)
// .expect(httpStatus.CREATED);
// expect(res.body).toEqual({
// id: expect.anything(),
// name: newPlatform.name,
// metadata: newPlatform.metadata,
// community: communityOne._id.toHexString(),
// disconnectedAt: null,
// connectedAt: expect.anything(),
// });
// const dbPlatform = await Platform.findById(res.body.id);
// expect(dbPlatform).toBeDefined();
// expect(dbPlatform).toMatchObject({
// name: newPlatform.name,
// metadata: newPlatform.metadata,
// });
// const dbCommunity = await Community.findById(res.body.community);
// expect(dbCommunity).toMatchObject({
// id: communityOne._id.toHexString(),
// name: communityOne.name,
// avatarURL: communityOne.avatarURL,
// users: [userOne._id],
// });
// });
test('should return 201 and successfully create new mediaWiki platform if data is ok', async () => {
userOne.communities = [communityOne._id];
communityOne.users = [userOne._id];
await insertCommunities([communityOne]);
await insertUsers([userOne]);
newPlatform = {
name: 'mediaWiki',
community: communityOne._id,
metadata: {
baseURL: 'base',
},
};
const res = await request(app)
.post(`/api/v1/platforms`)
.set('Authorization', `Bearer ${userOneAccessToken}`)
.send(newPlatform)
.expect(httpStatus.CREATED);
expect(res.body).toEqual({
id: expect.anything(),
name: newPlatform.name,
metadata: newPlatform.metadata,
community: communityOne._id.toHexString(),
disconnectedAt: null,
connectedAt: expect.anything(),
});
const dbPlatform = await Platform.findById(res.body.id);
expect(dbPlatform).toBeDefined();
expect(dbPlatform).toMatchObject({
name: newPlatform.name,
metadata: newPlatform.metadata,
});
const dbCommunity = await Community.findById(res.body.community);
expect(dbCommunity).toMatchObject({
id: communityOne._id.toHexString(),
name: communityOne.name,
avatarURL: communityOne.avatarURL,
users: [userOne._id],
});
});

Comment on lines +642 to +705
// test('should return 200 and successfully update hivemind module if platform is mediaWiki', async () => {
// await insertCommunities([communityOne, communityTwo, communityThree]);
// await insertUsers([userOne, userTwo]);
// await insertModules([moduleOne, moduleTwo]);

// updateBody.options = {
// platforms: [
// {
// platform: platformOne._id,
// metadata: {
// pageIds: ['1'],
// },
// name: PlatformNames.MediaWiki,
// },
// ],
// };
// const res = await request(app)
// .patch(`/api/v1/modules/${moduleTwo._id}`)
// .set('Authorization', `Bearer ${userOneAccessToken}`)
// .send(updateBody)
// .expect(httpStatus.OK);

// expect(res.body).toEqual({
// id: moduleTwo._id.toHexString(),
// name: moduleTwo.name,
// community: communityTwo._id.toHexString(),
// options: {
// platforms: [
// {
// _id: expect.anything(),
// platform: expect.anything(),
// metadata: {
// answering: {
// selectedChannels: ['1234'],
// },
// learning: {
// selectedChannels: ['8765', '1234'],
// fromDate: new Date('2024-03-18T07:46:51.493+00:00').toISOString(),
// },
// },
// name: 'discord',
// },
// {
// _id: expect.anything(),
// platform: platformOne._id.toHexString(),
// metadata: {
// pageIds: ['1'],
// },
// name: PlatformNames.MediaWiki,
// },
// ],
// },
// });

// const dbModule = await Module.findById(res.body.id);
// expect(dbModule).toBeDefined();
// // TODO: fix below code
// // expect(dbModule?.options).toMatchObject({
// // id: moduleOne._id.toHexString(),
// // name: moduleOne.name,
// // community: communityOne._id.toHexString(),
// // options: updateBody.options
// // });
// });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment the test case for PlatformNames.MediaWiki to ensure it is executed and validated.

- //     test('should return 200 and successfully update hivemind module if platform is mediaWiki', async () => {
- //       await insertCommunities([communityOne, communityTwo, communityThree]);
- //       await insertUsers([userOne, userTwo]);
- //       await insertModules([moduleOne, moduleTwo]);
- //
- //       updateBody.options = {
- //         platforms: [
- //           {
- //             platform: platformOne._id,
- //             metadata: {
- //               pageIds: ['1'],
- //             },
- //             name: PlatformNames.MediaWiki,
- //           },
- //         ],
- //       };
- //       const res = await request(app)
- //         .patch(`/api/v1/modules/${moduleTwo._id}`)
- //         .set('Authorization', `Bearer ${userOneAccessToken}`)
- //         .send(updateBody)
- //         .expect(httpStatus.OK);
- //
- //       expect(res.body).toEqual({
- //         id: moduleTwo._id.toHexString(),
- //         name: moduleTwo.name,
- //         community: communityTwo._id.toHexString(),
- //         options: {
- //           platforms: [
- //             {
- //               _id: expect.anything(),
- //               platform: expect.anything(),
- //               metadata: {
- //                 answering: {
- //                   selectedChannels: ['1234'],
- //                 },
- //                 learning: {
- //                   selectedChannels: ['8765', '1234'],
- //                   fromDate: new Date('2024-03-18T07:46:51.493+00:00').toISOString(),
- //                 },
- //               },
- //               name: 'discord',
- //             },
- //             {
- //               _id: expect.anything(),
- //               platform: platformOne._id.toHexString(),
- //               metadata: {
- //                 pageIds: ['1'],
- //               },
- //               name: PlatformNames.MediaWiki,
- //             },
- //           ],
- //         },
- //       });
- //
- //       const dbModule = await Module.findById(res.body.id);
- //       expect(dbModule).toBeDefined();
- //       // TODO: fix below code
- //       // expect(dbModule?.options).toMatchObject({
- //       //     id: moduleOne._id.toHexString(),
- //       //     name: moduleOne.name,
- //       //     community: communityOne._id.toHexString(),
- //       //     options: updateBody.options
- //       // });
- //     });

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// test('should return 200 and successfully update hivemind module if platform is mediaWiki', async () => {
// await insertCommunities([communityOne, communityTwo, communityThree]);
// await insertUsers([userOne, userTwo]);
// await insertModules([moduleOne, moduleTwo]);
// updateBody.options = {
// platforms: [
// {
// platform: platformOne._id,
// metadata: {
// pageIds: ['1'],
// },
// name: PlatformNames.MediaWiki,
// },
// ],
// };
// const res = await request(app)
// .patch(`/api/v1/modules/${moduleTwo._id}`)
// .set('Authorization', `Bearer ${userOneAccessToken}`)
// .send(updateBody)
// .expect(httpStatus.OK);
// expect(res.body).toEqual({
// id: moduleTwo._id.toHexString(),
// name: moduleTwo.name,
// community: communityTwo._id.toHexString(),
// options: {
// platforms: [
// {
// _id: expect.anything(),
// platform: expect.anything(),
// metadata: {
// answering: {
// selectedChannels: ['1234'],
// },
// learning: {
// selectedChannels: ['8765', '1234'],
// fromDate: new Date('2024-03-18T07:46:51.493+00:00').toISOString(),
// },
// },
// name: 'discord',
// },
// {
// _id: expect.anything(),
// platform: platformOne._id.toHexString(),
// metadata: {
// pageIds: ['1'],
// },
// name: PlatformNames.MediaWiki,
// },
// ],
// },
// });
// const dbModule = await Module.findById(res.body.id);
// expect(dbModule).toBeDefined();
// // TODO: fix below code
// // expect(dbModule?.options).toMatchObject({
// // id: moduleOne._id.toHexString(),
// // name: moduleOne.name,
// // community: communityOne._id.toHexString(),
// // options: updateBody.options
// // });
// });
test('should return 200 and successfully update hivemind module if platform is mediaWiki', async () => {
await insertCommunities([communityOne, communityTwo, communityThree]);
await insertUsers([userOne, userTwo]);
await insertModules([moduleOne, moduleTwo]);
updateBody.options = {
platforms: [
{
platform: platformOne._id,
metadata: {
pageIds: ['1'],
},
name: PlatformNames.MediaWiki,
},
],
};
const res = await request(app)
.patch(`/api/v1/modules/${moduleTwo._id}`)
.set('Authorization', `Bearer ${userOneAccessToken}`)
.send(updateBody)
.expect(httpStatus.OK);
expect(res.body).toEqual({
id: moduleTwo._id.toHexString(),
name: moduleTwo.name,
community: communityTwo._id.toHexString(),
options: {
platforms: [
{
_id: expect.anything(),
platform: expect.anything(),
metadata: {
answering: {
selectedChannels: ['1234'],
},
learning: {
selectedChannels: ['8765', '1234'],
fromDate: new Date('2024-03-18T07:46:51.493+00:00').toISOString(),
},
},
name: 'discord',
},
{
_id: expect.anything(),
platform: platformOne._id.toHexString(),
metadata: {
pageIds: ['1'],
},
name: PlatformNames.MediaWiki,
},
],
},
});
const dbModule = await Module.findById(res.body.id);
expect(dbModule).toBeDefined();
// TODO: fix below code
// expect(dbModule?.options).toMatchObject({
// id: moduleOne._id.toHexString(),
// name: moduleOne.name,
// community: communityOne._id.toHexString(),
// options: updateBody.options
// });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants