UNPKG

2.31 kBJavaScriptView Raw
1var assert = require('assert');
2var decorator = require('..').decorator;
3var fixtures = require('./fixtures');
4
5var tenant = fixtures.load('tenant.json');
6
7describe('ac hipchat decorator', function () {
8
9 var decorate;
10 var testLocalBaseUrl = 'http://example.com/hipchat';
11 var testAuthToken = '1234acbd';
12 var testService = {test: true};
13
14 function testServicesFactory(tenant) {
15 return {testService: testService};
16 }
17
18 describe('in production', function () {
19
20 beforeEach(function *() {
21 decorate = decorator('production', testLocalBaseUrl, testServicesFactory);
22 });
23
24 it('should return a decorate function for a given service factory, local base url, and node env', function *() {
25 var decorate = decorator('production', testLocalBaseUrl, testServicesFactory);
26 assert.equal(typeof decorate, 'function')
27 });
28
29 it('should return a populated decoration object given a tenant in production mode', function *() {
30 var decorate = decorator('production', testLocalBaseUrl, testServicesFactory);
31 var decoration = decorate(tenant, testAuthToken);
32 var tenantBaseUrl = tenant.links.base;
33 assert.deepEqual(decoration.testService, testService);
34 assert.deepEqual(decoration.locals, {
35 localBaseUrl: testLocalBaseUrl,
36 tenantBaseUrl: tenantBaseUrl,
37 tenantScriptUrl: tenantBaseUrl + '/atlassian-connect/all.js',
38 tenantStylesheetUrl: tenantBaseUrl + '/atlassian-connect/all.css',
39 authToken: testAuthToken
40 });
41 });
42
43 });
44
45 describe('not in production', function () {
46
47 beforeEach(function *() {
48 decorate = decorator('development', testLocalBaseUrl, testServicesFactory);
49 });
50
51 it('should return a populated decoration object given a tenant in non-production mode', function *() {
52 var decoration = decorate(tenant, testAuthToken);
53 var tenantBaseUrl = tenant.links.base;
54 assert.deepEqual(decoration.testService, testService);
55 assert.deepEqual(decoration.locals, {
56 localBaseUrl: testLocalBaseUrl,
57 tenantBaseUrl: tenantBaseUrl,
58 tenantScriptUrl: tenantBaseUrl + '/atlassian-connect/all-debug.js',
59 tenantStylesheetUrl: tenantBaseUrl + '/atlassian-connect/all-debug.css',
60 authToken: testAuthToken
61 });
62 });
63
64 });
65
66});