Преглед изворни кода

add tests for GrowiPluginService

Yuki Takei пре 2 година
родитељ
комит
3c02df37a7

+ 48 - 2
apps/app/src/features/growi-plugin/server/services/growi-plugin/growi-plugin.integ.ts

@@ -2,19 +2,22 @@ import fs from 'fs';
 import path from 'path';
 
 import { PLUGIN_STORING_PATH } from '../../consts';
+import { GrowiPlugin } from '../../models';
 
 import { growiPluginService } from './growi-plugin';
 
 describe('Installing a GROWI template plugin', () => {
 
-  it('should success', async() => {
+  it('install() should success', async() => {
     // when
     const result = await growiPluginService.install({
       url: 'https://github.com/weseek/growi-plugin-templates-for-office',
     });
+    const count = await GrowiPlugin.count({ 'meta.name': 'growi-plugin-templates-for-office' });
 
     // expect
     expect(result).toEqual('growi-plugin-templates-for-office');
+    expect(count).toBe(1);
     expect(fs.existsSync(path.join(
       PLUGIN_STORING_PATH,
       'weseek',
@@ -22,7 +25,11 @@ describe('Installing a GROWI template plugin', () => {
     ))).toBeTruthy();
   });
 
-  it('should success (re-install)', async() => {
+  it('install() should success (re-install)', async() => {
+    // confirm
+    const count1 = await GrowiPlugin.count({ 'meta.name': 'growi-plugin-templates-for-office' });
+    expect(count1).toBe(1);
+
     // setup
     const dummyFilePath = path.join(
       PLUGIN_STORING_PATH,
@@ -37,10 +44,49 @@ describe('Installing a GROWI template plugin', () => {
     const result = await growiPluginService.install({
       url: 'https://github.com/weseek/growi-plugin-templates-for-office',
     });
+    const count2 = await GrowiPlugin.count({ 'meta.name': 'growi-plugin-templates-for-office' });
 
     // expect
     expect(result).toEqual('growi-plugin-templates-for-office');
+    expect(count2).toBe(1);
     expect(fs.existsSync(dummyFilePath)).toBeFalsy(); // the dummy file should be removed
   });
 
 });
+
+describe('Installing a GROWI theme plugin', () => {
+
+  it('install() should success', async() => {
+    // when
+    const result = await growiPluginService.install({
+      url: 'https://github.com/weseek/growi-plugin-theme-welcome-to-fumiya-room',
+    });
+    const count = await GrowiPlugin.count({ 'meta.name': 'growi-plugin-theme-welcome-to-fumiya-room' });
+
+    // expect
+    expect(result).toEqual('growi-plugin-theme-welcome-to-fumiya-room');
+    expect(count).toBe(1);
+    expect(fs.existsSync(path.join(
+      PLUGIN_STORING_PATH,
+      'weseek',
+      'growi-plugin-theme-welcome-to-fumiya-room',
+    ))).toBeTruthy();
+  });
+
+  it('findThemePlugin() should return data with metadata and manifest', async() => {
+    // confirm
+    const count = await GrowiPlugin.count({ 'meta.name': 'growi-plugin-theme-welcome-to-fumiya-room' });
+    expect(count).toBe(1);
+
+    // when
+    const results = await growiPluginService.findThemePlugin('welcome-to-fumiya-room');
+
+    // expect
+    // expect(results).not.toBeNull();
+    // assert(results != null);
+    // expect(results.growiPlugin).not.toBeNull();
+    // expect(results.themeMetadata).not.toBeNull();
+    // expect(results.themeHref).not.toBeNull();
+  });
+
+});