1 | 'use strict';
|
2 |
|
3 | const assert = require('assert');
|
4 | const helper = require('./_helper');
|
5 |
|
6 |
|
7 | let pubsub = new helper.createMockConfigClient({
|
8 | key: 'key',
|
9 | secret: 'secret'
|
10 | });
|
11 |
|
12 | let events = {
|
13 | 'com.test.event': null,
|
14 | 'com.test.topic.*': null,
|
15 | 'com.test.*.interior': null,
|
16 | 'com.splatted.**': null
|
17 | };
|
18 | let topics = Object.keys(events);
|
19 |
|
20 | const url = new URL('http://un:pw@axwaylocal.com');
|
21 | pubsub.config = {
|
22 | url: url.href,
|
23 | can_consume: true,
|
24 | auth_type: 'basic',
|
25 | auth_user: url.username,
|
26 | auth_pass: url.password,
|
27 | events,
|
28 | topics
|
29 | };
|
30 |
|
31 | describe('validation', function () {
|
32 |
|
33 | it('should validate exact event name matches', function () {
|
34 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.event'), 'com.test.event');
|
35 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.event', topics), 'com.test.event');
|
36 | });
|
37 |
|
38 | it('should validate events matching wildcard terminus segment', function () {
|
39 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.topic.anything'), 'com.test.topic.*');
|
40 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.topic.anything', topics), 'com.test.topic.*');
|
41 | });
|
42 |
|
43 | it('should validate events matching wildcard interior segment', function () {
|
44 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.anything.interior'), 'com.test.*.interior');
|
45 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.anything.interior', topics), 'com.test.*.interior');
|
46 | });
|
47 |
|
48 | it('should validate events matching double-splatted topic', function () {
|
49 | assert.strictEqual(pubsub.hasSubscribedTopic('com.splatted.shortName'), 'com.splatted.**');
|
50 | assert.strictEqual(pubsub.hasSubscribedTopic('com.splatted.a.much.longer.event.name'), 'com.splatted.**');
|
51 | assert.strictEqual(pubsub.hasSubscribedTopic('com.splatted.shortName', topics), 'com.splatted.**');
|
52 | assert.strictEqual(pubsub.hasSubscribedTopic('com.splatted.a.much.longer.event.name', topics), 'com.splatted.**');
|
53 | });
|
54 |
|
55 | it('should not validate unsubscribed event topics', function () {
|
56 | assert.strictEqual(pubsub.hasSubscribedTopic('com.invalid.event'), null);
|
57 | assert.strictEqual(pubsub.hasSubscribedTopic('com.invalid.event', topics), null);
|
58 | });
|
59 |
|
60 | it('should not validate descendant topics', function () {
|
61 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.event.descendant'), null);
|
62 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.topic.wildcard.descendant'), null);
|
63 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.wildcard.interior.descendant'), null);
|
64 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.event.descendant', topics), null);
|
65 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.topic.wildcard.descendant', topics), null);
|
66 | assert.strictEqual(pubsub.hasSubscribedTopic('com.test.wildcard.interior.descendant', topics), null);
|
67 | });
|
68 | });
|