UNPKG

3.81 kBJavaScriptView Raw
1var assert = require('assert');
2var transform = require('..').transform;
3
4describe('ac hipchat descriptor transform', function () {
5
6 describe('descriptor with capabilities', function () {
7 var options = {
8 name: 'test-add-on',
9 displayName: 'Test Add-on',
10 description: 'A test add-on',
11 version: '0.0.1',
12 author: {
13 name: 'Atlassian',
14 url: 'http://atlassian.com'
15 }
16 };
17 var urls = {
18 base: 'http://localhost:3000',
19 homepage: '/',
20 descriptor: '/addon/capabilities',
21 installable: '/addon/installable'
22 };
23
24 it('should populate defaults from options and urls', function () {
25 var descriptor = {
26 capabilities: {}
27 };
28 assert.deepEqual(transform(descriptor, options, urls), {
29 key: 'test-add-on',
30 name: 'Test Add-on',
31 description: 'A test add-on',
32 version: '0.0.1',
33 vendor: {
34 name: 'Atlassian',
35 url: 'http://atlassian.com'
36 },
37 links: {
38 self: 'http://localhost:3000/addon/capabilities',
39 homepage: 'http://localhost:3000/'
40 },
41 capabilities: {
42 hipchatApiConsumer: {
43 scopes: []
44 },
45 installable: {
46 allowGlobal: false,
47 allowRoom: false,
48 callbackUrl: 'http://localhost:3000/addon/installable'
49 }
50 }
51 });
52 });
53
54 it('should make path urls full urls', function () {
55 var descriptor = {
56 links: {
57 self: '/addon/capabilities',
58 homepage: '/'
59 },
60 capabilities: {
61 installable: {
62 callbackUrl: '/addon/installable'
63 },
64 webhook: [{
65 event: 'room_enter',
66 url: '/addon/webhook'
67 }],
68 configurable: {
69 url: '/configure'
70 }
71 }
72 };
73 assert.deepEqual(transform(descriptor, options, urls), {
74 key: 'test-add-on',
75 name: 'Test Add-on',
76 description: 'A test add-on',
77 version: '0.0.1',
78 vendor: {
79 name: 'Atlassian',
80 url: 'http://atlassian.com'
81 },
82 links: {
83 self: 'http://localhost:3000/addon/capabilities',
84 homepage: 'http://localhost:3000/'
85 },
86 capabilities: {
87 hipchatApiConsumer: {
88 scopes: []
89 },
90 installable: {
91 allowGlobal: false,
92 allowRoom: false,
93 callbackUrl: 'http://localhost:3000/addon/installable'
94 },
95 webhook: [{
96 event: 'room_enter',
97 name: '90183e0516adf37661caa9efdb79c8d1472f992a',
98 url: 'http://localhost:3000/addon/webhook?name=90183e0516adf37661caa9efdb79c8d1472f992a'
99 }],
100 configurable: {
101 url: 'http://localhost:3000/configure'
102 }
103 }
104 });
105 });
106
107 it('should not overwrite explicit values', function () {
108 var descriptor = {
109 key: 'custom-key',
110 name: 'Custom Name',
111 description: 'A custom description',
112 version: '1.1.1',
113 vendor: {
114 name: 'Custom Vendor',
115 url: 'http://custom.com'
116 },
117 links: {
118 self: 'http://custom.com/addon/capabilities',
119 homepage: 'http://custom.com'
120 },
121 capabilities: {
122 hipchatApiConsumer: {
123 scopes: ['send_notification']
124 },
125 installable: {
126 allowGlobal: true,
127 allowRoom: true,
128 callbackUrl: 'http://custom.com/installable'
129 },
130 configurable: {
131 url: 'http://custom.com/configure'
132 }
133 }
134 };
135 assert.deepEqual(transform(descriptor, options, urls), descriptor);
136 });
137 });
138
139});