liudong
2023-05-29 340f156319b863525e50e900c58e59b86ecb3d5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const should = require("should");
const request = require('supertest');
const express = require('express');
const bodyParser = require("body-parser");
 
var app;
 
var NR_TEST_UTILS = require("nr-test-utils");
 
var plugins = NR_TEST_UTILS.require("@node-red/editor-api/lib/admin/plugins");
 
describe("api/editor/plugins", function() {
    const pluginList = [
        {
            "id": "test-module/test-set",
            "enabled": true,
            "local": false,
            "plugins": [
                {
                    "type": "foo",
                    "id": "a-plugin",
                    "module": "test-module"
                },
                {
                    "type": "bar",
                    "id": "a-plugin2",
                    "module": "test-module"
                },
                {
                    "type": "foo",
                    "id": "a-plugin3",
                    "module": "test-module"
                }
            ]
        },
        {
            "id": "test-module/test-disabled-set",
            "enabled": false,
            "local": false,
            "plugins": []
        }
    ];
    const pluginConfigs = `
<!-- --- [red-plugin:test-module/test-set] --- -->
test-module-config`;
 
    const pluginCatalogs = { "test-module": {"foo": "bar"}};
 
    before(function() {
        app = express();
        app.use(bodyParser.json());
        app.get("/plugins",plugins.getAll);
        app.get("/plugins/messages",plugins.getCatalogs);
 
        plugins.init({
            plugins: {
                getPluginList: async function() { return pluginList },
                getPluginConfigs: async function() { return pluginConfigs },
                getPluginCatalogs: async function() { return pluginCatalogs }
            }
        })
    });
 
    it('returns the list of plugins', function(done) {
        request(app)
        .get("/plugins")
        .set('Accept', 'application/json')
        .expect(200)
        .end(function(err,res) {
            if (err) {
                return done(err);
            }
            try {
                JSON.stringify(res.body).should.eql(JSON.stringify(pluginList));
                done();
            } catch(err) {
                done(err)
            }
        });
    });
    it('returns the plugin configs', function(done) {
        request(app)
        .get("/plugins")
        .set('Accept', 'text/html')
        .expect(200)
        .expect(pluginConfigs)
        .end(function(err,res) {
            if (err) {
                return done(err);
            }
            done();
        });
    });
    it('returns the plugin catalogs', function(done) {
        request(app)
        .get("/plugins/messages")
        .set('Accept', 'application/json')
        .expect(200)
        .end(function(err,res) {
            if (err) {
                return done(err);
            }
            try {
                JSON.stringify(res.body).should.eql(JSON.stringify(pluginCatalogs));
                done();
            } catch(err) {
                done(err)
            }
        });
    });
});