-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
82 lines (73 loc) · 1.78 KB
/
test.js
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
const test = require('tap').test;
const Fastify = require('fastify');
const fastifyObjectionJsClasses = require('./plugin');
test('invalid models option', (t) => {
register(t, {}, function (err, fastify) {
t.throws(function () {
throw err;
});
t.notOk(fastify.objection);
t.end();
});
});
test('classes option is not Array', (t) => {
register(t, { classes: {} }, function (err, fastify) {
t.throws(function () {
throw err;
});
t.notOk(fastify.objection);
t.end();
});
});
test('empty classes option', (t) => {
register(t, { classes: [] }, function (err, fastify) {
t.throws(function () {
throw err;
});
t.notOk(fastify.objection);
t.end();
});
});
test('supplied classes option are invalid ', (t) => {
register(t, { classes: ['lodash'] }, function (err, fastify) {
t.throws(function () {
throw err;
});
t.notOk(fastify.objection);
t.end();
});
});
test('double register of the same plugin', (t) => {
const fastify = Fastify();
t.teardown(() => fastify.close());
fastify
.register(fastifyObjectionJsClasses, {
classes: ['fn'],
})
.register(fastifyObjectionJsClasses, {
classes: ['fn'],
})
.ready((err) => {
t.ok(err);
t.equal(
err.message,
'fastify-objectionjs-classes has already registered.'
);
t.end();
});
});
test('load a valid class', (t) => {
register(t, { classes: ['fn'] }, function (err, fastify) {
t.error(err);
t.ok(fastify.objectionjs);
t.ok(fastify.objectionjs.fn);
t.end();
});
});
function register(t, options, callback) {
const fastify = Fastify();
t.teardown(() => fastify.close());
fastify
.register(fastifyObjectionJsClasses, options)
.ready((err) => callback(err, fastify));
}