Yuki Takei 2 лет назад
Родитель
Сommit
3af4eec386

+ 28 - 3
apps/app/src/features/growi-plugin/server/models/growi-plugin.integ.ts

@@ -8,16 +8,28 @@ describe('GrowiPlugin find methods', () => {
     await GrowiPlugin.insertMany([
     await GrowiPlugin.insertMany([
       {
       {
         isEnabled: false,
         isEnabled: false,
-        installedPath: 'weseek/growi-plugin-unenabled',
+        installedPath: 'weseek/growi-plugin-unenabled1',
         organizationName: 'weseek',
         organizationName: 'weseek',
         origin: {
         origin: {
-          url: 'https://github.com/weseek/growi-plugin-unenabled',
+          url: 'https://github.com/weseek/growi-plugin-unenabled1',
         },
         },
         meta: {
         meta: {
-          name: '@growi/growi-plugin-unenabled',
+          name: '@growi/growi-plugin-unenabled1',
           types: [GrowiPluginType.Script],
           types: [GrowiPluginType.Script],
         },
         },
       },
       },
+      {
+        isEnabled: false,
+        installedPath: 'weseek/growi-plugin-unenabled2',
+        organizationName: 'weseek',
+        origin: {
+          url: 'https://github.com/weseek/growi-plugin-unenabled2',
+        },
+        meta: {
+          name: '@growi/growi-plugin-unenabled2',
+          types: [GrowiPluginType.Template],
+        },
+      },
       {
       {
         isEnabled: true,
         isEnabled: true,
         installedPath: 'weseek/growi-plugin-example1',
         installedPath: 'weseek/growi-plugin-example1',
@@ -59,4 +71,17 @@ describe('GrowiPlugin find methods', () => {
     });
     });
   });
   });
 
 
+  describe('.findEnabledPluginsByType', () => {
+    it("shoud returns documents which type is 'template'", async() => {
+      // when
+      const results = await GrowiPlugin.findEnabledPluginsByType(GrowiPluginType.Template);
+
+      const pluginNames = results.map(p => p.meta.name);
+
+      // then
+      expect(results.length === 1).toBeTruthy();
+      expect(pluginNames.includes('@growi/growi-plugin-example2')).toBeTruthy();
+    });
+  });
+
 });
 });

+ 2 - 2
apps/app/src/features/growi-plugin/server/models/growi-plugin.ts

@@ -51,11 +51,11 @@ growiPluginSchema.statics.findEnabledPlugins = async function(): Promise<IGrowiP
 };
 };
 
 
 growiPluginSchema.statics.findEnabledPluginsByType = async function<T extends GrowiPluginType>(
 growiPluginSchema.statics.findEnabledPluginsByType = async function<T extends GrowiPluginType>(
-    types: T,
+    type: T,
 ): Promise<IGrowiPlugin<IGrowiPluginMetaByType<T>>[]> {
 ): Promise<IGrowiPlugin<IGrowiPluginMetaByType<T>>[]> {
   return this.find({
   return this.find({
     isEnabled: true,
     isEnabled: true,
-    'meta.types': { $in: types },
+    'meta.types': { $in: type },
   });
   });
 };
 };