gell-dispatch 0.0.1 → 0.1.0

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.
@@ -0,0 +1,81 @@
1
+ const assert = require('assert');
2
+
3
+ const Registry = require('../../registry');
4
+
5
+ describe('action kind', function() {
6
+ let registry, MODULE;
7
+
8
+ beforeEach(function() {
9
+ registry = new Registry(require('../../kind/action'));
10
+
11
+ MODULE = {
12
+ __metadata: {
13
+ name: 'session.update',
14
+ description: 'updates a session',
15
+ triggers: {
16
+ action: {
17
+ params: { attr: 'string', count: { type: 'number', optional: true } },
18
+ context: { session$: 'complex' },
19
+ roles: ['admin'],
20
+ },
21
+ effect: {}
22
+ }
23
+ },
24
+
25
+ action: () => {},
26
+ effect: () => {}
27
+ };
28
+ })
29
+
30
+ it('registers by __metadata.name', function() {
31
+ registry.register(MODULE);
32
+
33
+ assert.strictEqual(registry.get('session.update'), MODULE);
34
+ })
35
+
36
+ it('rejects a module without an action function', function() {
37
+ delete MODULE.action;
38
+
39
+ assert.throws(() => registry.register(MODULE), {
40
+ name: 'AssertionError',
41
+ message: 'action (name=session.update) must define an action function'
42
+ });
43
+ })
44
+
45
+ it('rejects a module without __metadata', function() {
46
+ assert.throws(() => registry.register({ action() {} }), { name: 'AssertionError' });
47
+ })
48
+
49
+ it('describes name, description and triggers', function() {
50
+ registry.register(MODULE);
51
+
52
+ assert.deepStrictEqual(registry.describe('session.update'), {
53
+ name: 'session.update',
54
+ description: 'updates a session',
55
+ triggers: {
56
+ action: {
57
+ params: [{ name: 'attr', type: 'string', optional: false }, { name: 'count', type: 'number', optional: true }],
58
+ context: [{ name: 'session$', type: 'complex', optional: false }],
59
+ roles: ['admin'],
60
+ },
61
+ effect: { params: [], context: [] }
62
+ }
63
+ });
64
+ })
65
+
66
+ it('describes a module without triggers', function() {
67
+ delete MODULE.__metadata.triggers;
68
+
69
+ registry.register(MODULE);
70
+
71
+ assert.deepStrictEqual(registry.describe('session.update').triggers, {});
72
+ })
73
+
74
+ it('does not share data with the declaration', function() {
75
+ registry.register(MODULE);
76
+
77
+ registry.describe('session.update').triggers.action.roles.push('driver');
78
+
79
+ assert.deepStrictEqual(MODULE.__metadata.triggers.action.roles, ['admin']);
80
+ })
81
+ })
@@ -0,0 +1,81 @@
1
+ const assert = require('assert');
2
+
3
+ const Registry = require('../../registry');
4
+
5
+ describe('snapshot kind', function() {
6
+ let registry, MODULE;
7
+
8
+ beforeEach(function() {
9
+ registry = new Registry(require('../../kind/snapshot'));
10
+
11
+ MODULE = {
12
+ __metadata: {
13
+ name: 'session.update',
14
+ description: 'updates a session',
15
+ triggers: {
16
+ api: {
17
+ params: { attr: 'string', count: { type: 'number', optional: true } },
18
+ context: { session$: 'complex' },
19
+ roles: ['admin'],
20
+ },
21
+ effect: {}
22
+ }
23
+ },
24
+
25
+ api: () => {},
26
+ effect: () => {}
27
+ };
28
+ })
29
+
30
+ it('registers by __metadata.name', function() {
31
+ registry.register(MODULE);
32
+
33
+ assert.strictEqual(registry.get('session.update'), MODULE);
34
+ })
35
+
36
+ it('rejects a module without an api function', function() {
37
+ delete MODULE.api;
38
+
39
+ assert.throws(() => registry.register(MODULE), {
40
+ name: 'AssertionError',
41
+ message: 'snapshot (name=session.update) must define an api function'
42
+ });
43
+ })
44
+
45
+ it('rejects a module without __metadata', function() {
46
+ assert.throws(() => registry.register({ api() {} }), { name: 'AssertionError' });
47
+ })
48
+
49
+ it('describes name, description and triggers', function() {
50
+ registry.register(MODULE);
51
+
52
+ assert.deepStrictEqual(registry.describe('session.update'), {
53
+ name: 'session.update',
54
+ description: 'updates a session',
55
+ triggers: {
56
+ api: {
57
+ params: [{ name: 'attr', type: 'string', optional: false }, { name: 'count', type: 'number', optional: true }],
58
+ context: [{ name: 'session$', type: 'complex', optional: false }],
59
+ roles: ['admin'],
60
+ },
61
+ effect: { params: [], context: [] }
62
+ }
63
+ });
64
+ })
65
+
66
+ it('describes a module without triggers', function() {
67
+ delete MODULE.__metadata.triggers;
68
+
69
+ registry.register(MODULE);
70
+
71
+ assert.deepStrictEqual(registry.describe('session.update').triggers, {});
72
+ })
73
+
74
+ it('does not share data with the declaration', function() {
75
+ registry.register(MODULE);
76
+
77
+ registry.describe('session.update').triggers.api.roles.push('driver');
78
+
79
+ assert.deepStrictEqual(MODULE.__metadata.triggers.api.roles, ['admin']);
80
+ })
81
+ })
@@ -0,0 +1,54 @@
1
+ const assert = require('assert');
2
+
3
+ const Registry = require('../../registry');
4
+
5
+ describe('type kind', function() {
6
+ let registry, SESSION;
7
+
8
+ beforeEach(function() {
9
+ registry = new Registry(require('../../kind/type'));
10
+
11
+ SESSION = {
12
+ TYPE: 'GELL#SESSION',
13
+ model: { name: 'gell.session', attributes: { type: 'string', parentId: 'uuid' } }
14
+ };
15
+ })
16
+
17
+ it('registers by model.name', function() {
18
+ registry.register(SESSION);
19
+
20
+ assert.strictEqual(registry.get('gell.session'), SESSION);
21
+ })
22
+
23
+ it('rejects a module without TYPE', function() {
24
+ delete SESSION.TYPE;
25
+
26
+ assert.throws(() => registry.register(SESSION), { name: 'AssertionError', message: 'type (name=gell.session) must define TYPE' });
27
+ })
28
+
29
+ it('rejects a module without a model', function() {
30
+ assert.throws(() => registry.register({ TYPE: 'GELL#SESSION' }), { name: 'AssertionError' });
31
+ })
32
+
33
+ it('describes map attributes', function() {
34
+ registry.register(SESSION);
35
+
36
+ assert.deepStrictEqual(registry.describe('gell.session'), { name: 'gell.session', type: 'GELL#SESSION', attributes: ['type', 'parentId'] });
37
+ })
38
+
39
+ it('describes array attributes', function() {
40
+ SESSION.model.attributes = [{ name: 'type' }, { name: 'parentId' }];
41
+
42
+ registry.register(SESSION);
43
+
44
+ assert.deepStrictEqual(registry.describe('gell.session').attributes, ['type', 'parentId']);
45
+ })
46
+
47
+ it('describes a model without attributes', function() {
48
+ delete SESSION.model.attributes;
49
+
50
+ registry.register(SESSION);
51
+
52
+ assert.deepStrictEqual(registry.describe('gell.session').attributes, []);
53
+ })
54
+ })