@projectinvicta/nails 3.0.0 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/init.js +0 -4
- package/lib/Nails.ts +1 -0
- package/lib/Router.ts +1 -1
- package/package.json +5 -6
- package/tests/bin/init.spec.js +3 -0
- package/tests/controller.spec.js +61 -0
- package/tests/nails.spec.js +4 -0
- package/tests/router.spec.js +105 -0
- package/tests/services.integration.spec.js +210 -0
- package/vite.config.ts +23 -0
- package/spec/bin/init.spec.js +0 -0
- package/spec/controller.spec.js +0 -59
- package/spec/nails.spec.js +0 -1
- package/spec/router.spec.js +0 -101
- package/spec/services.integration.spec.js +0 -324
- /package/{spec → tests}/services/integration/README.md +0 -0
- /package/{spec → tests}/services/integration/client/css/styles.css +0 -0
- /package/{spec → tests}/services/integration/client/download.jpg +0 -0
- /package/{spec → tests}/services/integration/client/favicon.ico +0 -0
- /package/{spec → tests}/services/integration/client/index.html +0 -0
- /package/{spec → tests}/services/integration/client/js/client.js +0 -0
- /package/{spec → tests}/services/integration/client/js/components/app.jsx +0 -0
- /package/{spec → tests}/services/integration/config/db.ts +0 -0
- /package/{spec → tests}/services/integration/config/mimes.js +0 -0
- /package/{spec → tests}/services/integration/config/routes.js +0 -0
- /package/{spec → tests}/services/integration/config/service.js +0 -0
- /package/{spec → tests}/services/integration/config/ssl/certificate.pem +0 -0
- /package/{spec → tests}/services/integration/config/ssl/csr.csr +0 -0
- /package/{spec → tests}/services/integration/config/ssl/key.pem +0 -0
- /package/{spec → tests}/services/integration/config/ssl/private_key.pem +0 -0
- /package/{spec → tests}/services/integration/config/ssl/public_key.pem +0 -0
- /package/{spec → tests}/services/integration/package.json +0 -0
- /package/{spec → tests}/services/integration/server/controllers/classbased_controller.js +0 -0
- /package/{spec → tests}/services/integration/server/controllers/default_json_controller.js +0 -0
- /package/{spec → tests}/services/integration/server/controllers/error_controller.js +0 -0
- /package/{spec → tests}/services/integration/server/controllers/home_controller.js +0 -0
- /package/{spec → tests}/services/integration/server/controllers/json_controller.js +0 -0
- /package/{spec → tests}/services/integration/server/controllers/manualrenderasync_controller.js +0 -0
- /package/{spec → tests}/services/integration/server/controllers/mjs_controller.mjs +0 -0
- /package/{spec → tests}/services/integration/server/controllers/modeltest_controller.js +0 -0
- /package/{spec → tests}/services/integration/server/controllers/websocket_controller.js +0 -0
- /package/{spec → tests}/services/integration/server/models/dog.js +0 -0
- /package/{spec → tests}/services/integration/server/models/owner.js +0 -0
- /package/{spec → tests}/services/integration/server/views/defaultjson/testnojson.ejs +0 -0
- /package/{spec → tests}/services/integration/server/views/testreact/testreact.ejs +0 -0
- /package/{spec → tests}/services/integration/server.js +0 -0
package/bin/lib/init.js
CHANGED
|
@@ -3,14 +3,10 @@
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import {copySync} from 'fs-extra/esm';
|
|
6
|
-
import {exec} from 'child_process';
|
|
7
|
-
// var exec = require('child_process').exec;
|
|
8
6
|
var args = process.argv.slice(2);
|
|
9
7
|
|
|
10
8
|
var appName = args[0];
|
|
11
9
|
var originalDir = process.cwd();
|
|
12
|
-
var lastDir;
|
|
13
|
-
var notRoot = true;
|
|
14
10
|
|
|
15
11
|
// Make sure an app name was passed
|
|
16
12
|
if ( !appName ) {
|
package/lib/Nails.ts
CHANGED
package/lib/Router.ts
CHANGED
|
@@ -85,7 +85,7 @@ class NailsRouter extends EventEmitter {
|
|
|
85
85
|
console.log('the action is:', controller, action, params);
|
|
86
86
|
console.log('the params are:', params);
|
|
87
87
|
console.log('ws router emitting:', 'dispatchTo:' + controller);
|
|
88
|
-
this.emit('dispatchTo:' + controller, action, params, request,
|
|
88
|
+
this.emit('dispatchTo:' + controller, {action, params, request, ws});
|
|
89
89
|
|
|
90
90
|
if (!(request as any).handled_by_controller) {
|
|
91
91
|
params.error = { message: 'controller ' + controller + ' does not exist' };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectinvicta/nails",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "A node.js webserver scaffold",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"copyreadme": "node bin/convertreadmetohtml.js",
|
|
15
|
-
"test": "
|
|
16
|
-
"debug": "
|
|
15
|
+
"test": "vitest run ./tests",
|
|
16
|
+
"debug": "vitest --inspect-brk run ./tests",
|
|
17
17
|
"test_init": "bash bin/test/test_init.sh"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
@@ -48,10 +48,9 @@
|
|
|
48
48
|
"@types/express": "*",
|
|
49
49
|
"@types/express-ws": "*",
|
|
50
50
|
"@types/node": "*",
|
|
51
|
-
"chai": "*",
|
|
52
51
|
"chai-http": "*",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
52
|
+
"vite": "^8.0.1",
|
|
53
|
+
"vitest": "^4.1.0"
|
|
55
54
|
},
|
|
56
55
|
"config": {
|
|
57
56
|
"mongodbMemoryServer": {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import Controller from '../lib/Controller.ts';
|
|
3
|
+
import {EventEmitter} from 'node:events';
|
|
4
|
+
|
|
5
|
+
class TestController extends Controller {
|
|
6
|
+
testAction() {};
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
class TestEs6Controller extends Controller {
|
|
10
|
+
testEs6Action() {
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('Controller', () => {
|
|
17
|
+
describe('Controller.setRouter', () => {
|
|
18
|
+
it('should set Controller.router to the router', () => {
|
|
19
|
+
const router = {};
|
|
20
|
+
Controller.setRouter(router);
|
|
21
|
+
expect(Controller.router).toBe(router);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('Controller.constructor', () => {
|
|
25
|
+
it('should set the appropriate listener on the router',
|
|
26
|
+
() => {
|
|
27
|
+
const mockRouter = new EventEmitter();
|
|
28
|
+
const mockParams = {_controller: "test"};
|
|
29
|
+
const mockRequest = {};
|
|
30
|
+
const mockResponse = {headersSent: true};
|
|
31
|
+
Controller.setRouter(mockRouter);
|
|
32
|
+
const testController = new TestEs6Controller();
|
|
33
|
+
const spy = vi.spyOn(testController, "testEs6Action");
|
|
34
|
+
|
|
35
|
+
mockRouter.emit(
|
|
36
|
+
'dispatchTo:testes6',
|
|
37
|
+
{action: 'testEs6Action', params: mockParams, request: mockRequest, response: mockResponse});
|
|
38
|
+
|
|
39
|
+
expect(spy).toHaveBeenCalledWith(
|
|
40
|
+
mockParams, mockRequest, mockResponse);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('#_do', () => {
|
|
44
|
+
it.todo('should call the function on the controller matching the given action');
|
|
45
|
+
it.todo('should call 404 if the action does not exist on the controller instance');
|
|
46
|
+
it.todo('should call 500 if the action throws an error');
|
|
47
|
+
it.todo('should attempt to render a view');
|
|
48
|
+
it.todo('should not render a view if data has already been sent to the client');
|
|
49
|
+
it.todo('should not render a view if _async is true');
|
|
50
|
+
it.todo('should not render a view if async is true on the action');
|
|
51
|
+
});
|
|
52
|
+
describe('#404', () => {
|
|
53
|
+
it.todo('should test something');
|
|
54
|
+
});
|
|
55
|
+
describe('#500', () => {
|
|
56
|
+
it.todo('should test something');
|
|
57
|
+
});
|
|
58
|
+
describe('#public', () => {
|
|
59
|
+
it.todo('should test something');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import Router from '../lib/Router.ts';
|
|
3
|
+
import express_app from '../lib/application.ts';
|
|
4
|
+
|
|
5
|
+
express_app.set("public_root", import.meta.dirname + "/services/integration/public");
|
|
6
|
+
const testRoutes = [
|
|
7
|
+
['GET', '^/$', {controller: 'testController', action: 'testAction'}],
|
|
8
|
+
['GET', /^\/public\/*/, {public: true}]
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
let router;
|
|
12
|
+
|
|
13
|
+
describe('Router', () => {
|
|
14
|
+
describe('route', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
router = new Router(testRoutes);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it(`should emit dispatchTo:application if a registered controller does
|
|
20
|
+
not match the action`, async () => {
|
|
21
|
+
const mockRequest = {
|
|
22
|
+
method: 'get',
|
|
23
|
+
url: 'http://www.test.com/public/test.html'
|
|
24
|
+
};
|
|
25
|
+
const mockResponse = {};
|
|
26
|
+
const expectedAction = 404;
|
|
27
|
+
|
|
28
|
+
const dispatchPromise = new Promise(resolve => {
|
|
29
|
+
router.on('dispatchTo:application', ({action, params, request, response}) => {
|
|
30
|
+
resolve({action, params, request, response});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
router.route(mockRequest, mockResponse);
|
|
35
|
+
|
|
36
|
+
const {action, params, request, response} = await dispatchPromise;
|
|
37
|
+
|
|
38
|
+
expect(action).toEqual(expectedAction);
|
|
39
|
+
expect(typeof(params)).toBe('object');
|
|
40
|
+
expect(params.file).toBeUndefined();
|
|
41
|
+
expect(request).toBe(mockRequest);
|
|
42
|
+
expect(response).toBe(mockResponse);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should emit dispatch:<controller> event based on the params', async () => {
|
|
46
|
+
const mockParams = {
|
|
47
|
+
_controller: "test",
|
|
48
|
+
_action: "testAction"
|
|
49
|
+
};
|
|
50
|
+
const mockRequest = {
|
|
51
|
+
method: 'get',
|
|
52
|
+
url: 'http://www.test.com/',
|
|
53
|
+
params: mockParams
|
|
54
|
+
};
|
|
55
|
+
const mockResponse = {};
|
|
56
|
+
const expectedAction = 'testAction';
|
|
57
|
+
|
|
58
|
+
const dispatchPromise = new Promise(resolve => {
|
|
59
|
+
router.on('dispatchTo:test', ({action, params, request, response}) => {
|
|
60
|
+
resolve({action, params, request, response});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
router.route(mockRequest, mockResponse);
|
|
65
|
+
|
|
66
|
+
const {action, params, request, response} = await dispatchPromise;
|
|
67
|
+
|
|
68
|
+
expect(action).toEqual(expectedAction);
|
|
69
|
+
expect(params._controller).toEqual(mockParams._controller);
|
|
70
|
+
expect(params._action).toEqual(mockParams._action);
|
|
71
|
+
expect(request).toBe(mockRequest);
|
|
72
|
+
expect(response).toBe(mockResponse);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should emit dispatch:<controller> event based on the url query", async () => {
|
|
76
|
+
const mockQuery = {
|
|
77
|
+
_controller: "test",
|
|
78
|
+
_action: "testAction"
|
|
79
|
+
};
|
|
80
|
+
const mockRequest = {
|
|
81
|
+
method: 'get',
|
|
82
|
+
url: 'http://www.test.com/',
|
|
83
|
+
query: mockQuery
|
|
84
|
+
};
|
|
85
|
+
const mockResponse = {};
|
|
86
|
+
const expectedAction = 'testAction';
|
|
87
|
+
|
|
88
|
+
const dispatchPromise = new Promise(resolve => {
|
|
89
|
+
router.on('dispatchTo:test', ({action, params, request, response}) => {
|
|
90
|
+
resolve({action, params, request, response});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
router.route(mockRequest, mockResponse);
|
|
95
|
+
|
|
96
|
+
const {action, params, request, response} = await dispatchPromise;
|
|
97
|
+
|
|
98
|
+
expect(action).toEqual(expectedAction);
|
|
99
|
+
expect(params._controller).toEqual(mockQuery._controller);
|
|
100
|
+
expect(params._action).toEqual(mockQuery._action);
|
|
101
|
+
expect(request).toBe(mockRequest);
|
|
102
|
+
expect(response).toBe(mockResponse);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { chai, describe, it, expect, beforeAll } from 'vitest';
|
|
2
|
+
import {default as chaiHttp, request} from 'chai-http';
|
|
3
|
+
import WebSocket from 'ws';
|
|
4
|
+
|
|
5
|
+
let nails;
|
|
6
|
+
var express_app;
|
|
7
|
+
|
|
8
|
+
chai.use(chaiHttp);
|
|
9
|
+
|
|
10
|
+
const makeRequest = (path) => {
|
|
11
|
+
return new Promise(resolve => {
|
|
12
|
+
request.execute(express_app)
|
|
13
|
+
.get(path)
|
|
14
|
+
.end((err, res) => resolve(res));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("Integration: Sequelize", () => {
|
|
19
|
+
beforeAll(async () => {
|
|
20
|
+
try {
|
|
21
|
+
nails = (await import('./services/integration/server.js')).default;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
console.log("could not import server");
|
|
24
|
+
console.log(e);
|
|
25
|
+
}
|
|
26
|
+
express_app = nails.application;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("/listowners", () => {
|
|
30
|
+
it('should return an empty array if no owners', async () => {
|
|
31
|
+
const res = await makeRequest('/listowners');
|
|
32
|
+
expect(res).to.have.status(200);
|
|
33
|
+
expect(JSON.parse(res.text)).to.have.lengthOf(0);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("/listowneddogs", () => {
|
|
38
|
+
it('should return an empty array if no owned dogs', async () => {
|
|
39
|
+
const res = await makeRequest('/listowneddogs');
|
|
40
|
+
expect(res).to.have.status(200);
|
|
41
|
+
expect(JSON.parse(res.text)).to.have.lengthOf(0);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("GET /", () => {
|
|
46
|
+
it('should return the expected JSON from index', async () => {
|
|
47
|
+
const res = await makeRequest('/');
|
|
48
|
+
expect(res).to.have.status(200);
|
|
49
|
+
expect(res.text).to.equal(JSON.stringify({ home_index: true }));
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("GET /classbased", () => {
|
|
54
|
+
it('should return the expected JSON from index', async () => {
|
|
55
|
+
const res = await makeRequest('/classbased');
|
|
56
|
+
expect(res).to.have.status(200);
|
|
57
|
+
expect(res.text).to.equal(JSON.stringify({ classbased_index: true }));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("Get /classbased/arbi/trary/testLocalRoutes", () => {
|
|
62
|
+
it("Should respect the defined local route and return the expected JSON", async () => {
|
|
63
|
+
const res = await makeRequest('/classbased/arbi00/trary00/testLocalRoutes');
|
|
64
|
+
expect(res).to.have.status(200);
|
|
65
|
+
expect(res.text).to.equal(JSON.stringify({ testLocalRoutes: true }));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("Should not rewrite local route prefix and return the expected JSON", async () => {
|
|
69
|
+
const res = await makeRequest('/cl4ssb4sed/arbi/trary/testLocalRoutes');
|
|
70
|
+
expect(res).to.have.status(200);
|
|
71
|
+
expect(res.text).to.equal(JSON.stringify({ testLocalRoutes: true }));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("Should rewrite local route prefix, './' and return the expected JSON", async () => {
|
|
75
|
+
const res = await makeRequest('/classbased/arbi/trary/testLocalRoutes');
|
|
76
|
+
expect(res).to.have.status(200);
|
|
77
|
+
expect(res.text).to.equal(JSON.stringify({ testLocalRoutes: true }));
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("Get /defaultjson/arbi/trary", () => {
|
|
82
|
+
it("Should default to json if not present in route options", async () => {
|
|
83
|
+
const res = await makeRequest('/defaultjson/arbi/trary/testautojson');
|
|
84
|
+
expect(res).to.have.status(200);
|
|
85
|
+
expect(res.text).to.equal(JSON.stringify({ json_testautojson: true }));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("Should autoassign the action if not present in route options", async () => {
|
|
89
|
+
const res = await makeRequest('/defaultjson/arbi/trary/testautoaction');
|
|
90
|
+
expect(res).to.have.status(200);
|
|
91
|
+
expect(res.text).to.equal(JSON.stringify({ json_testautoaction: true }));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("Should not render json if route options explicitly say not to", async () => {
|
|
95
|
+
const res = await makeRequest('/defaultjson/arbi/trary/testjsonoverridden');
|
|
96
|
+
expect(res).to.have.status(200);
|
|
97
|
+
expect(res.text).to.equal('I am some arbitrary text');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("GET /^\\/(\\w+)\\/(\\w+)$/i", () => {
|
|
102
|
+
it('should route to home_controller#testaction', async () => {
|
|
103
|
+
const res = await makeRequest('/home/testaction');
|
|
104
|
+
expect(res).to.have.status(200);
|
|
105
|
+
expect(res.text).to.equal(JSON.stringify({ home_testaction: true }));
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should route to classbased_controller#testaction', async () => {
|
|
109
|
+
const res = await makeRequest('/classbased/testaction');
|
|
110
|
+
expect(res).to.have.status(200);
|
|
111
|
+
expect(res.text).to.equal(JSON.stringify({ classbased_testaction: true }));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should render correctly when a promise is returned', async () => {
|
|
115
|
+
const res = await makeRequest('/classbased/testpromise');
|
|
116
|
+
expect(res).to.have.status(200);
|
|
117
|
+
expect(res.text).to.equal(JSON.stringify({ classbased_testpromise: true }));
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("GET /error/fivehundred", () => {
|
|
122
|
+
it('should log the stack trace', async () => {
|
|
123
|
+
const res = await makeRequest('/error/fivehundred/500');
|
|
124
|
+
expect(res).to.have.status(500);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should return meaningful JSON', async () => {
|
|
128
|
+
const res = await makeRequest('/error/fivehundred');
|
|
129
|
+
expect(res).to.have.status(500);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("WebSockets", () => {
|
|
134
|
+
it("should listen on /", () => new Promise(resolve => {
|
|
135
|
+
const wsClient = new WebSocket("ws://localhost:3333/");
|
|
136
|
+
wsClient.on('message', (message) => {
|
|
137
|
+
expect(message.toString()).to.equal("It worked");
|
|
138
|
+
wsClient.close();
|
|
139
|
+
});
|
|
140
|
+
wsClient.on('close', () => resolve());
|
|
141
|
+
}));
|
|
142
|
+
|
|
143
|
+
it("should listen on /voodoo", () => new Promise(resolve => {
|
|
144
|
+
const wsClient = new WebSocket("ws://localhost:3333/voodoo");
|
|
145
|
+
wsClient.on('message', (message) => {
|
|
146
|
+
expect(message.toString()).to.equal("Voodoo worked");
|
|
147
|
+
wsClient.close();
|
|
148
|
+
});
|
|
149
|
+
wsClient.on('close', () => resolve());
|
|
150
|
+
}));
|
|
151
|
+
|
|
152
|
+
it("should not listen on /voodootwo", () => new Promise(resolve => {
|
|
153
|
+
const wsClient = new WebSocket("ws://localhost:3333/voodootwo");
|
|
154
|
+
wsClient.on('close', (code, reason) => {
|
|
155
|
+
resolve();
|
|
156
|
+
});
|
|
157
|
+
}));
|
|
158
|
+
|
|
159
|
+
it.todo("should be closed with the correct code if the action is absent");
|
|
160
|
+
it.todo("should be closed with the correct code if the controller is absent");
|
|
161
|
+
it.todo("should correctly parse the params");
|
|
162
|
+
it.todo("should correctly handle dynamic controller and action");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe("GET /json/:action", () => {
|
|
166
|
+
it.todo('should render params if nothing is returned by the action');
|
|
167
|
+
|
|
168
|
+
it('should render the returned object as json', async () => {
|
|
169
|
+
const res = await makeRequest('/json/testaction');
|
|
170
|
+
expect(res).to.have.status(200);
|
|
171
|
+
expect(res.text).to.equal(JSON.stringify({ json_testaction: true }));
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('should asynchronously render the resolved promise as json', async () => {
|
|
175
|
+
const res = await makeRequest('/json/testpromise');
|
|
176
|
+
expect(res).to.have.status(200);
|
|
177
|
+
expect(res.text).to.equal(JSON.stringify({ json_testpromise: true }));
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("Get /ManualRenderAsync", () => {
|
|
182
|
+
it("./testmanualrenderasync Should not throw an exception after manually rendering json asynchronously", async () => {
|
|
183
|
+
const res = await makeRequest("/manualrenderasync/testmanualrenderasync");
|
|
184
|
+
expect(res).to.have.status(200);
|
|
185
|
+
expect(res.text).to.equal(JSON.stringify({ json_testmanualrenderasync: true }));
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("./testmanualrenderexplicitasync Should not throw an exception after manually rendering json asynchronously using the async function tag", async () => {
|
|
189
|
+
const res = await makeRequest("/manualrenderasync/testmanualrenderexplicitasync");
|
|
190
|
+
expect(res).to.have.status(200);
|
|
191
|
+
expect(res.text).to.equal(JSON.stringify({ json_testmanualrenderexplicitasync: true }));
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe("Mongoose Model", () => {
|
|
196
|
+
it('should save to the correct database', async () => {
|
|
197
|
+
const dogName = "Penny";
|
|
198
|
+
const createRes = await makeRequest(`/modeltest/createdog?name=${dogName}`);
|
|
199
|
+
expect(createRes).to.have.status(200);
|
|
200
|
+
const dogId = createRes.text.replaceAll("\"", "");
|
|
201
|
+
const getRes = await makeRequest(`/modeltest/getdogbyid?id=${dogId}`);
|
|
202
|
+
const dogOnServer = JSON.parse(getRes.text);
|
|
203
|
+
expect(dogOnServer.name).to.equal(dogName);
|
|
204
|
+
expect(dogOnServer.good).to.be.true;
|
|
205
|
+
expect(dogOnServer).to.have.property('id');
|
|
206
|
+
expect(dogOnServer).to.have.property('createdAt');
|
|
207
|
+
expect(dogOnServer).to.have.property('updatedAt');
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="vitest" />
|
|
2
|
+
|
|
3
|
+
// import react from '@vitejs/plugin-react'
|
|
4
|
+
import { defineConfig } from 'vite'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
|
|
7
|
+
// https://vitejs.dev/config/
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
define: {
|
|
10
|
+
'process.env': {}
|
|
11
|
+
},
|
|
12
|
+
test: {
|
|
13
|
+
globals: true,
|
|
14
|
+
// environment: 'jsdom',
|
|
15
|
+
// setupFiles: './spec/setupTests.js',
|
|
16
|
+
},
|
|
17
|
+
resolve: {
|
|
18
|
+
alias: {
|
|
19
|
+
'@lib': path.resolve(__dirname, './lib'), // Alias '@' to the 'common' directory
|
|
20
|
+
'@server': path.resolve(__dirname, './server'), // Alias '@' to the 'server' directory
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
})
|
package/spec/bin/init.spec.js
DELETED
|
File without changes
|
package/spec/controller.spec.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import Controller from '../lib/Controller.ts';
|
|
2
|
-
import assert from 'assert';
|
|
3
|
-
import sinon from 'sinon';
|
|
4
|
-
import {EventEmitter} from 'node:events';
|
|
5
|
-
|
|
6
|
-
class TestController extends Controller {
|
|
7
|
-
testAction() {};
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
class TestEs6Controller extends Controller {
|
|
11
|
-
testEs6Action() {
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('Controller', function() {
|
|
18
|
-
describe('Controller.setRouter', function() {
|
|
19
|
-
it('should set Controller.router to the router', function() {
|
|
20
|
-
var router = {};
|
|
21
|
-
Controller.setRouter(router);
|
|
22
|
-
assert(Controller.router === router);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
describe('Controller.constructor', function() {
|
|
26
|
-
it('should set the appropriate listener on the router',
|
|
27
|
-
function() {
|
|
28
|
-
let mockRouter = new EventEmitter();
|
|
29
|
-
let mockParams = {_controller: "test"};
|
|
30
|
-
let mockRequest = {};
|
|
31
|
-
let mockResponse = {headersSent: true};
|
|
32
|
-
Controller.setRouter(mockRouter);
|
|
33
|
-
let testController = new TestEs6Controller();
|
|
34
|
-
sinon.spy(testController, "testEs6Action");
|
|
35
|
-
|
|
36
|
-
mockRouter.emit(
|
|
37
|
-
'dispatchTo:testes6',
|
|
38
|
-
{action: 'testEs6Action', params: mockParams, request: mockRequest, response: mockResponse});
|
|
39
|
-
|
|
40
|
-
assert(testController.testEs6Action.calledWith(
|
|
41
|
-
mockParams, mockRequest, mockResponse));
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
describe('#_do', function() {
|
|
45
|
-
it('should call the function on the controller matching the given action');
|
|
46
|
-
it('should call 404 if the action does not exist on the controller instance');
|
|
47
|
-
it('should call 500 if the action throws an error');
|
|
48
|
-
it('should attempt to render a view');
|
|
49
|
-
it('should not render a view if data has already been sent to the client');
|
|
50
|
-
it('should not render a view if _async is true');
|
|
51
|
-
it('should not render a view if async is true on the action');
|
|
52
|
-
});
|
|
53
|
-
describe('#404', function() {
|
|
54
|
-
});
|
|
55
|
-
describe('#500', function() {
|
|
56
|
-
});
|
|
57
|
-
describe('#public', function() {
|
|
58
|
-
});
|
|
59
|
-
});
|
package/spec/nails.spec.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// TODO test all initialization here
|
package/spec/router.spec.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// var express_app = require('../lib/application.js');
|
|
2
|
-
import Router from '../lib/Router.ts';
|
|
3
|
-
import assert from 'assert';
|
|
4
|
-
import express_app from '../lib/application.ts';
|
|
5
|
-
|
|
6
|
-
express_app.set("public_root", import.meta.dirname + "/services/integration/public");
|
|
7
|
-
var testRoutes = [
|
|
8
|
-
['GET', '^/$', {controller: 'testController', action: 'testAction'}],
|
|
9
|
-
['GET', /^\/public\/*/, {public: true}]
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
var router;
|
|
13
|
-
|
|
14
|
-
describe('Router', function() {
|
|
15
|
-
describe('route', function() {
|
|
16
|
-
beforeEach(function() {
|
|
17
|
-
router = new Router(testRoutes);
|
|
18
|
-
});
|
|
19
|
-
it(`should emit dispatchTo:application if a registered controller does
|
|
20
|
-
not match the action`,
|
|
21
|
-
function(done) {
|
|
22
|
-
var mockRequest = {
|
|
23
|
-
method: 'get',
|
|
24
|
-
url: 'http://www.test.com/public/test.html'
|
|
25
|
-
};
|
|
26
|
-
var mockResponse = {};
|
|
27
|
-
var expectedAction = '404';
|
|
28
|
-
var testFunctionCalled;
|
|
29
|
-
router.on('dispatchTo:application', test);
|
|
30
|
-
|
|
31
|
-
function test({action, params, request, response}) {
|
|
32
|
-
testFunctionCalled = true;
|
|
33
|
-
assert.equal(action, expectedAction);
|
|
34
|
-
assert.equal(typeof(params), 'object');
|
|
35
|
-
assert.equal(params.file, undefined);
|
|
36
|
-
assert.equal(request, mockRequest);
|
|
37
|
-
assert.equal(response, mockResponse);
|
|
38
|
-
done();
|
|
39
|
-
}
|
|
40
|
-
router.route(mockRequest, mockResponse);
|
|
41
|
-
if (!testFunctionCalled) done('testFailed');
|
|
42
|
-
});
|
|
43
|
-
it('should emit dispatch:<controller> event based on the params',
|
|
44
|
-
function(done) {
|
|
45
|
-
const mockParams = {
|
|
46
|
-
_controller: "test",
|
|
47
|
-
_action: "testAction"
|
|
48
|
-
};
|
|
49
|
-
var mockRequest = {
|
|
50
|
-
method: 'get',
|
|
51
|
-
url: 'http://www.test.com/',
|
|
52
|
-
params: mockParams
|
|
53
|
-
};
|
|
54
|
-
var mockResponse = {};
|
|
55
|
-
var expectedAction = 'testAction';
|
|
56
|
-
var testFunctionCalled;
|
|
57
|
-
router.on('dispatchTo:test', test);
|
|
58
|
-
|
|
59
|
-
function test({action, params, request, response}) {
|
|
60
|
-
testFunctionCalled = true;
|
|
61
|
-
assert.equal(action, expectedAction);
|
|
62
|
-
assert.equal(params._controller, mockParams._controller);
|
|
63
|
-
assert.equal(params._action, mockParams._action);
|
|
64
|
-
assert.equal(request, mockRequest);
|
|
65
|
-
assert.equal(response, mockResponse);
|
|
66
|
-
done();
|
|
67
|
-
}
|
|
68
|
-
router.route(mockRequest, mockResponse);
|
|
69
|
-
if (!testFunctionCalled) done('testFailed');
|
|
70
|
-
});
|
|
71
|
-
it("should emit dispatch:<controller> event based on the url query",
|
|
72
|
-
function(done) {
|
|
73
|
-
const mockQuery = {
|
|
74
|
-
_controller: "test",
|
|
75
|
-
_action: "testAction"
|
|
76
|
-
};
|
|
77
|
-
var mockRequest = {
|
|
78
|
-
method: 'get',
|
|
79
|
-
url: 'http://www.test.com/',
|
|
80
|
-
query: mockQuery
|
|
81
|
-
};
|
|
82
|
-
var mockResponse = {};
|
|
83
|
-
var expectedAction = 'testAction';
|
|
84
|
-
var testFunctionCalled;
|
|
85
|
-
router.on('dispatchTo:test', test);
|
|
86
|
-
|
|
87
|
-
function test({action, params, request, response}) {
|
|
88
|
-
testFunctionCalled = true;
|
|
89
|
-
assert.equal(action, expectedAction);
|
|
90
|
-
assert.equal(params._controller, mockQuery._controller);
|
|
91
|
-
assert.equal(params._action, mockQuery._action);
|
|
92
|
-
assert.equal(request, mockRequest);
|
|
93
|
-
assert.equal(response, mockResponse);
|
|
94
|
-
done();
|
|
95
|
-
}
|
|
96
|
-
router.route(mockRequest, mockResponse);
|
|
97
|
-
if (!testFunctionCalled) done('testFailed');
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
// Import the dependencies for testing
|
|
2
|
-
import * as chai from 'chai';
|
|
3
|
-
import { default as chaiHttp, request } from "chai-http";
|
|
4
|
-
// import chaiHttp from 'chai-http';
|
|
5
|
-
import { assert } from 'chai';
|
|
6
|
-
// import { WebSocket } from 'ws';
|
|
7
|
-
import WebSocket from 'ws';
|
|
8
|
-
// const WebSocket = require('ws');
|
|
9
|
-
|
|
10
|
-
let nails;
|
|
11
|
-
var express_app;
|
|
12
|
-
// const {MongoMemoryServer} = require('mongodb-memory-server');
|
|
13
|
-
let mongod = null;
|
|
14
|
-
|
|
15
|
-
// Configure chai
|
|
16
|
-
chai.use(chaiHttp);
|
|
17
|
-
chai.should();
|
|
18
|
-
|
|
19
|
-
describe("Integration: Sequelize", function () {
|
|
20
|
-
before(async function () {
|
|
21
|
-
// this.timeout(30000);
|
|
22
|
-
try {
|
|
23
|
-
nails = (await import('./services/integration/server.js')).default;
|
|
24
|
-
} catch (e) {
|
|
25
|
-
console.log("could not import server");
|
|
26
|
-
console.log(e);
|
|
27
|
-
}
|
|
28
|
-
console.log("got here");
|
|
29
|
-
express_app = nails.application;
|
|
30
|
-
});
|
|
31
|
-
describe("/listowners", function () {
|
|
32
|
-
it('should return an empty array if no owners', function (done) {
|
|
33
|
-
request.execute(express_app)
|
|
34
|
-
.get('/listowners')
|
|
35
|
-
.end((err, res) => {
|
|
36
|
-
res.should.have.status(200);
|
|
37
|
-
assert(JSON.parse(res.text).length == 0);
|
|
38
|
-
done();
|
|
39
|
-
});
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
describe("/listowneddogs", function () {
|
|
43
|
-
it('should return an empty array if no owned dogs', function (done) {
|
|
44
|
-
request.execute(express_app)
|
|
45
|
-
.get('/listowneddogs')
|
|
46
|
-
.end((err, res) => {
|
|
47
|
-
res.should.have.status(200);
|
|
48
|
-
assert(JSON.parse(res.text).length == 0);
|
|
49
|
-
done();
|
|
50
|
-
});
|
|
51
|
-
})
|
|
52
|
-
})
|
|
53
|
-
describe("GET /", function () {
|
|
54
|
-
it('should return the expected JSON from index', function (done) {
|
|
55
|
-
request.execute(express_app)
|
|
56
|
-
.get('/')
|
|
57
|
-
.end((err, res) => {
|
|
58
|
-
res.should.have.status(200);
|
|
59
|
-
assert(res.text == JSON.stringify({ home_index: true }));
|
|
60
|
-
done();
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
describe("GET /classbased", function () {
|
|
65
|
-
it('should return the expected JSON from index', function (done) {
|
|
66
|
-
request.execute(express_app)
|
|
67
|
-
.get('/classbased')
|
|
68
|
-
.end((err, res) => {
|
|
69
|
-
res.should.have.status(200);
|
|
70
|
-
assert(res.text == JSON.stringify({ classbased_index: true }));
|
|
71
|
-
done();
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
describe("Get /classbased/arbi/trary/testLocalRoutes", function () {
|
|
76
|
-
it("Should respect the defined local route and return the expected JSON", function (done) {
|
|
77
|
-
request.execute(express_app)
|
|
78
|
-
.get('/classbased/arbi00/trary00/testLocalRoutes')
|
|
79
|
-
.end((err, res) => {
|
|
80
|
-
res.should.have.status(200);
|
|
81
|
-
assert(res.text == JSON.stringify({ testLocalRoutes: true }));
|
|
82
|
-
done();
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
it("Should not rewrite local route prefix and return the expected JSON", function (done) {
|
|
86
|
-
request.execute(express_app)
|
|
87
|
-
.get('/cl4ssb4sed/arbi/trary/testLocalRoutes')
|
|
88
|
-
.end((err, res) => {
|
|
89
|
-
res.should.have.status(200);
|
|
90
|
-
assert(res.text == JSON.stringify({ testLocalRoutes: true }));
|
|
91
|
-
done();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
it("Should rewrite local route prefix, './' and return the expected JSON", function (done) {
|
|
95
|
-
request.execute(express_app)
|
|
96
|
-
.get('/classbased/arbi/trary/testLocalRoutes')
|
|
97
|
-
.end((err, res) => {
|
|
98
|
-
res.should.have.status(200);
|
|
99
|
-
assert(res.text == JSON.stringify({ testLocalRoutes: true }));
|
|
100
|
-
done();
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
describe("Get /defaultjson/arbi/trary", function () {
|
|
105
|
-
it("Should default to json if not present in route options", function (done) {
|
|
106
|
-
request.execute(express_app)
|
|
107
|
-
.get('/defaultjson/arbi/trary/testautojson')
|
|
108
|
-
.end((err, res) => {
|
|
109
|
-
res.should.have.status(200);
|
|
110
|
-
assert(res.text == JSON.stringify({ json_testautojson: true }));
|
|
111
|
-
done();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
it("Should autoassign the action if not present in route options", function (done) {
|
|
115
|
-
request.execute(express_app)
|
|
116
|
-
.get('/defaultjson/arbi/trary/testautoaction')
|
|
117
|
-
.end((err, res) => {
|
|
118
|
-
res.should.have.status(200);
|
|
119
|
-
assert(res.text == JSON.stringify({ json_testautoaction: true }));
|
|
120
|
-
done();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
it("Should not render json if route options explicitly say not to", function (done) {
|
|
124
|
-
request.execute(express_app)
|
|
125
|
-
.get('/defaultjson/arbi/trary/testjsonoverridden')
|
|
126
|
-
.end((err, res) => {
|
|
127
|
-
res.should.have.status(200);
|
|
128
|
-
assert(res.text == 'I am some arbitrary text');
|
|
129
|
-
done();
|
|
130
|
-
});
|
|
131
|
-
})
|
|
132
|
-
});
|
|
133
|
-
describe("GET /^\\/(\\w+)\\/(\\w+)$/i", function () {
|
|
134
|
-
it('should route to home_controller#testaction', function (done) {
|
|
135
|
-
request.execute(express_app)
|
|
136
|
-
.get('/home/testaction')
|
|
137
|
-
.end((err, res) => {
|
|
138
|
-
res.should.have.status(200);
|
|
139
|
-
assert(res.text == JSON.stringify({ home_testaction: true }));
|
|
140
|
-
done();
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
it('should route to classbased_controller#testaction', function (done) {
|
|
144
|
-
request.execute(express_app)
|
|
145
|
-
.get('/classbased/testaction')
|
|
146
|
-
.end((err, res) => {
|
|
147
|
-
res.should.have.status(200);
|
|
148
|
-
assert(res.text == JSON.stringify({ classbased_testaction: true }));
|
|
149
|
-
done();
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
it('should render correctly when a promise is returned', function (done) {
|
|
153
|
-
request.execute(express_app)
|
|
154
|
-
.get('/classbased/testpromise')
|
|
155
|
-
.end((err, res) => {
|
|
156
|
-
res.should.have.status(200);
|
|
157
|
-
assert(res.text == JSON.stringify({ classbased_testpromise: true }));
|
|
158
|
-
done();
|
|
159
|
-
});
|
|
160
|
-
})
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe("GET /error/fivehundred", function () {
|
|
164
|
-
it('should log the stack trace', function (done) {
|
|
165
|
-
request.execute(express_app)
|
|
166
|
-
.get('/error/fivehundred/500')
|
|
167
|
-
.end((err, res) => {
|
|
168
|
-
res.should.have.status(500);
|
|
169
|
-
//console.log(res.text);
|
|
170
|
-
//console.log(res);
|
|
171
|
-
//console.log(err);
|
|
172
|
-
done();
|
|
173
|
-
})
|
|
174
|
-
});
|
|
175
|
-
it('should return meaningful JSON', function (done) {
|
|
176
|
-
request.execute(express_app)
|
|
177
|
-
.get('/error/fivehundred')
|
|
178
|
-
.end((err, res) => {
|
|
179
|
-
res.should.have.status(500);
|
|
180
|
-
console.log("ZZZZZZZZZZ");
|
|
181
|
-
console.log(res.text);
|
|
182
|
-
//console.log(res.text);
|
|
183
|
-
//console.log(res);
|
|
184
|
-
//console.log(err);
|
|
185
|
-
done();
|
|
186
|
-
})
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe("WebSockets", function () {
|
|
191
|
-
it("should listen on /", function (done) {
|
|
192
|
-
this.timeout(2000);
|
|
193
|
-
var requester = request.execute(express_app).keepOpen();
|
|
194
|
-
var wsClient = new WebSocket("ws://localhost:3333/");
|
|
195
|
-
|
|
196
|
-
wsClient.on('close', () => done());
|
|
197
|
-
wsClient.on('message', (message) => {
|
|
198
|
-
assert(message == "It worked");
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
it("should listen on /voodoo", function (done) {
|
|
202
|
-
this.timeout(2000);
|
|
203
|
-
var requester = request.execute(express_app).keepOpen();
|
|
204
|
-
var wsClient = new WebSocket("ws://localhost:3333/voodoo");
|
|
205
|
-
|
|
206
|
-
wsClient.on('message', (message) => {
|
|
207
|
-
assert(message == "Voodoo worked");
|
|
208
|
-
});
|
|
209
|
-
wsClient.on('close', (code, reason) => done());
|
|
210
|
-
});
|
|
211
|
-
it("should not listen on /voodootwo", function (done) {
|
|
212
|
-
// TODO: this doesn't fail. Figure out why.
|
|
213
|
-
//done();
|
|
214
|
-
this.timeout(2000);
|
|
215
|
-
var requester = request.execute(express_app).keepOpen();
|
|
216
|
-
var wsClient = new WebSocket("ws://localhost:3333/voodootwo");
|
|
217
|
-
|
|
218
|
-
wsClient.on('close', (code, reason) => {
|
|
219
|
-
console.log('voodootwo closed', code, reason);
|
|
220
|
-
done();
|
|
221
|
-
});
|
|
222
|
-
debugger;
|
|
223
|
-
});
|
|
224
|
-
it("should be closed with the correct code if the action is absent");
|
|
225
|
-
it("should be closed with the correct code if the controller is absent");
|
|
226
|
-
it("should correctly parse the params");
|
|
227
|
-
it("should correctly handle dynamic controller and action");
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
describe("GET /json/:action", function () {
|
|
231
|
-
// TODO: Do we really want this behavior?
|
|
232
|
-
it('should render params if nothing is returned by the action',
|
|
233
|
-
// function (done) {
|
|
234
|
-
// request.execute(express_app)
|
|
235
|
-
// // Route to index action.
|
|
236
|
-
// .get('/json/testparams?testkey=testvalue')
|
|
237
|
-
// .end((err, res) => {
|
|
238
|
-
// res.should.have.status(200);
|
|
239
|
-
// assert(JSON.parse(res.text).testkey == "testvalue");
|
|
240
|
-
// done();
|
|
241
|
-
// });
|
|
242
|
-
// }
|
|
243
|
-
);
|
|
244
|
-
it('should render the returned object as json', function (done) {
|
|
245
|
-
request.execute(express_app)
|
|
246
|
-
.get('/json/testaction')
|
|
247
|
-
.end((err, res) => {
|
|
248
|
-
res.should.have.status(200);
|
|
249
|
-
assert(res.text == JSON.stringify({ json_testaction: true }));
|
|
250
|
-
done();
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
it('should asynchronously render the resolved promise as json',
|
|
254
|
-
function (done) {
|
|
255
|
-
request.execute(express_app)
|
|
256
|
-
.get('/json/testpromise')
|
|
257
|
-
.end((err, res) => {
|
|
258
|
-
res.should.have.status(200);
|
|
259
|
-
assert(res.text == JSON.stringify({ json_testpromise: true }));
|
|
260
|
-
done();
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
);
|
|
264
|
-
});
|
|
265
|
-
describe("Get /ManualRenderAsync", function () {
|
|
266
|
-
it("./testmanualrenderasync Should not throw an exception after manually"
|
|
267
|
-
+ " rendering json asynchronously",
|
|
268
|
-
done => {
|
|
269
|
-
request.execute(express_app)
|
|
270
|
-
.get("/manualrenderasync/testmanualrenderasync")
|
|
271
|
-
.end((err, res) => {
|
|
272
|
-
res.should.have.status(200);
|
|
273
|
-
assert(res.text ==
|
|
274
|
-
JSON.stringify({ json_testmanualrenderasync: true }));
|
|
275
|
-
done();
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it("./testmanualrenderexplicitasync Should not throw an exception after"
|
|
280
|
-
+ " manually rendering json asynchronously using the async function"
|
|
281
|
-
+ " tag",
|
|
282
|
-
done => {
|
|
283
|
-
request.execute(express_app)
|
|
284
|
-
.get("/manualrenderasync/testmanualrenderexplicitasync")
|
|
285
|
-
.end((err, res) => {
|
|
286
|
-
res.should.have.status(200);
|
|
287
|
-
assert(res.text ==
|
|
288
|
-
JSON.stringify({ json_testmanualrenderexplicitasync: true }));
|
|
289
|
-
done();
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
});
|
|
294
|
-
describe("Mongoose Model", function () {
|
|
295
|
-
beforeEach(async function () {
|
|
296
|
-
// Used to initialize mongod here
|
|
297
|
-
});
|
|
298
|
-
afterEach(async function () {
|
|
299
|
-
//await mongod.stop();
|
|
300
|
-
});
|
|
301
|
-
it('should save to the correct database', function (done) {
|
|
302
|
-
let dogName = "Penny";
|
|
303
|
-
let dogId = null;
|
|
304
|
-
request.execute(express_app)
|
|
305
|
-
.get(`/modeltest/createdog?name=${dogName}`)
|
|
306
|
-
.end((err, res) => {
|
|
307
|
-
res.should.have.status(200);
|
|
308
|
-
dogId = res.text.replaceAll("\"", "");
|
|
309
|
-
request.execute(express_app)
|
|
310
|
-
.get(`/modeltest/getdogbyid?id=${dogId}`)
|
|
311
|
-
.end((err, res) => {
|
|
312
|
-
const dogOnServer = JSON.parse(res.text);
|
|
313
|
-
assert.equal(dogOnServer.name, dogName);
|
|
314
|
-
assert.isTrue(dogOnServer.good);
|
|
315
|
-
assert.isDefined(dogOnServer.id);
|
|
316
|
-
assert.isDefined(dogOnServer.createdAt);
|
|
317
|
-
assert.isDefined(dogOnServer.updatedAt);
|
|
318
|
-
done();
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
});
|
|
324
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{spec → tests}/services/integration/server/controllers/manualrenderasync_controller.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|