github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/unit/services/token-test.js (about) 1 import Service from '@ember/service'; 2 import { module, test } from 'qunit'; 3 import { setupTest } from 'ember-qunit'; 4 import Pretender from 'pretender'; 5 6 module('Unit | Service | Token', function(hooks) { 7 setupTest(hooks); 8 9 hooks.beforeEach(function() { 10 this.subject = function() { 11 return this.owner.factoryFor('service:token').create(); 12 }; 13 }); 14 15 hooks.beforeEach(function() { 16 const mockSystem = Service.extend({ 17 activeRegion: 'region-1', 18 shouldIncludeRegion: true, 19 }); 20 21 this.owner.register('service:system', mockSystem); 22 this.system = this.owner.lookup('service:system'); 23 24 this.server = new Pretender(function() { 25 this.get('/path', () => [200, {}, null]); 26 }); 27 }); 28 29 hooks.afterEach(function() { 30 this.server.shutdown(); 31 }); 32 33 test('authorizedRequest includes the region param when the system service says to', function(assert) { 34 const token = this.subject(); 35 36 token.authorizedRequest('/path'); 37 assert.equal( 38 this.server.handledRequests.pop().url, 39 `/path?region=${this.system.get('activeRegion')}`, 40 'The region param is included when the system service shouldIncludeRegion property is true' 41 ); 42 43 this.system.set('shouldIncludeRegion', false); 44 45 token.authorizedRequest('/path'); 46 assert.equal( 47 this.server.handledRequests.pop().url, 48 '/path', 49 'The region param is not included when the system service shouldIncludeRegion property is false' 50 ); 51 }); 52 53 test('authorizedRawRequest bypasses adding the region param', function(assert) { 54 const token = this.subject(); 55 56 token.authorizedRawRequest('/path'); 57 assert.equal( 58 this.server.handledRequests.pop().url, 59 '/path', 60 'The region param is ommitted when making a raw request' 61 ); 62 }); 63 });