-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit test coverage for adding the region param to requests
- Loading branch information
1 parent
dbc18c9
commit ae464a0
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { getOwner } from '@ember/application'; | ||
import Service from '@ember/service'; | ||
import { moduleFor, test } from 'ember-qunit'; | ||
import Pretender from 'pretender'; | ||
|
||
moduleFor('service:token', 'Unit | Service | Token', { | ||
beforeEach() { | ||
const mockSystem = Service.extend({ | ||
activeRegion: 'region-1', | ||
shouldIncludeRegion: true, | ||
}); | ||
|
||
this.register('service:system', mockSystem); | ||
this.system = getOwner(this).lookup('service:system'); | ||
|
||
this.server = new Pretender(function() { | ||
this.get('/path', () => [200, {}, null]); | ||
}); | ||
}, | ||
afterEach() { | ||
this.server.shutdown(); | ||
}, | ||
subject() { | ||
return getOwner(this) | ||
.factoryFor('service:token') | ||
.create(); | ||
}, | ||
}); | ||
|
||
test('authorizedRequest includes the region param when the system service says to', function(assert) { | ||
const token = this.subject(); | ||
|
||
token.authorizedRequest('/path'); | ||
assert.equal( | ||
this.server.handledRequests.pop().url, | ||
`/path?region=${this.system.get('activeRegion')}`, | ||
'The region param is included when the system service shouldIncludeRegion property is true' | ||
); | ||
|
||
this.system.set('shouldIncludeRegion', false); | ||
|
||
token.authorizedRequest('/path'); | ||
assert.equal( | ||
this.server.handledRequests.pop().url, | ||
'/path', | ||
'The region param is not included when the system service shouldIncludeRegion property is false' | ||
); | ||
}); | ||
|
||
test('authorizedRawRequest bypasses adding the region param', function(assert) { | ||
const token = this.subject(); | ||
|
||
token.authorizedRawRequest('/path'); | ||
assert.equal( | ||
this.server.handledRequests.pop().url, | ||
'/path', | ||
'The region param is ommitted when making a raw request' | ||
); | ||
}); |