-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from ember-nexus/github-issue/92
Improved API Host Config Validation with Trailing Slash Removal
- Loading branch information
Showing
13 changed files
with
130 additions
and
9 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file.
Empty file.
4 changes: 2 additions & 2 deletions
4
docs/type/classes/Service_WebSdkConfiguration.WebSdkConfiguration.html
Large diffs are not rendered by default.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
src/EventSystem/NormalizedValueToRawValue/NormalizedValueToRawValueEventManager.ts
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
2 changes: 1 addition & 1 deletion
2
src/EventSystem/RawValueToNormalizedValue/RawValueToNormalizedValueEventManager.ts
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
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,109 @@ | ||
import { expect } from 'chai'; | ||
import { SinonSandbox, createSandbox } from 'sinon'; | ||
import { Container } from 'typedi'; | ||
|
||
import { Logger, WebSdkConfiguration } from '../../../src/Service'; | ||
import { validateTokenFromString } from '../../../src/Type/Definition'; | ||
import { TestLogger } from '../TestLogger'; | ||
|
||
describe('WebSdkConfiguration tests', () => { | ||
let sandbox: SinonSandbox; | ||
let testLogger: TestLogger; | ||
|
||
beforeEach(() => { | ||
sandbox = createSandbox(); | ||
|
||
testLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
Container.reset(); | ||
}); | ||
|
||
it('should return default values', async () => { | ||
const webSdkConfiguration = Container.get(WebSdkConfiguration); | ||
|
||
expect(webSdkConfiguration.getToken()).to.be.null; | ||
expect(webSdkConfiguration.getApiHost()).to.be.equal(''); | ||
expect(webSdkConfiguration.getElementCacheMaxEntries()).to.be.equal(100); | ||
expect(webSdkConfiguration.getCollectionCacheMaxEntries()).to.be.equal(50); | ||
expect(webSdkConfiguration.getCollectionPageSize()).to.be.equal(25); | ||
}); | ||
|
||
it('should correctly save the token', async () => { | ||
const webSdkConfiguration = Container.get(WebSdkConfiguration); | ||
const token = validateTokenFromString('secret-token:someToken'); | ||
|
||
expect(webSdkConfiguration.getToken()).to.be.null; | ||
webSdkConfiguration.setToken(token); | ||
expect(webSdkConfiguration.getToken()).to.be.equal(token); | ||
}); | ||
|
||
it('should correctly save the api host', async () => { | ||
const webSdkConfiguration = Container.get(WebSdkConfiguration); | ||
const apiHost = 'https://localhost'; | ||
|
||
expect(webSdkConfiguration.getApiHost()).to.be.equal(''); | ||
webSdkConfiguration.setApiHost(apiHost); | ||
expect(webSdkConfiguration.getApiHost()).to.be.equal(apiHost); | ||
}); | ||
|
||
it('should warn if the api host has a trailing slash', async () => { | ||
const webSdkConfiguration = Container.get(WebSdkConfiguration); | ||
const apiHost = 'https://localhost/'; | ||
|
||
expect(webSdkConfiguration.getApiHost()).to.be.equal(''); | ||
webSdkConfiguration.setApiHost(apiHost); | ||
expect(webSdkConfiguration.getApiHost()).to.not.be.equal(apiHost); | ||
expect(webSdkConfiguration.getApiHost()).to.be.equal('https://localhost'); | ||
expect( | ||
testLogger.assertWarnHappened( | ||
'Removed trailing slash from API host configuration due to internal requirement. Please check if trailing slash can be directly removed.', | ||
), | ||
).to.be.true; | ||
}); | ||
|
||
it('should warn if the api host has multiple trailing slashes', async () => { | ||
const webSdkConfiguration = Container.get(WebSdkConfiguration); | ||
const apiHost = 'https://localhost///'; | ||
|
||
expect(webSdkConfiguration.getApiHost()).to.be.equal(''); | ||
webSdkConfiguration.setApiHost(apiHost); | ||
expect(webSdkConfiguration.getApiHost()).to.not.be.equal(apiHost); | ||
expect(webSdkConfiguration.getApiHost()).to.be.equal('https://localhost'); | ||
expect( | ||
testLogger.assertWarnHappened( | ||
'Removed trailing slash from API host configuration due to internal requirement. Please check if trailing slash can be directly removed.', | ||
), | ||
).to.be.true; | ||
}); | ||
|
||
it('should correctly save the element cache max entries', async () => { | ||
const webSdkConfiguration = Container.get(WebSdkConfiguration); | ||
const elementCacheMaxEntries = 999; | ||
|
||
expect(webSdkConfiguration.getElementCacheMaxEntries()).to.be.equal(100); | ||
webSdkConfiguration.setElementCacheMaxEntries(elementCacheMaxEntries); | ||
expect(webSdkConfiguration.getElementCacheMaxEntries()).to.be.equal(elementCacheMaxEntries); | ||
}); | ||
|
||
it('should correctly save the collection cache max entries', async () => { | ||
const webSdkConfiguration = Container.get(WebSdkConfiguration); | ||
const collectionCacheMaxEntries = 999; | ||
|
||
expect(webSdkConfiguration.getCollectionCacheMaxEntries()).to.be.equal(50); | ||
webSdkConfiguration.setCollectionCacheMaxEntries(collectionCacheMaxEntries); | ||
expect(webSdkConfiguration.getCollectionCacheMaxEntries()).to.be.equal(collectionCacheMaxEntries); | ||
}); | ||
|
||
it('should correctly save the collection page size', async () => { | ||
const webSdkConfiguration = Container.get(WebSdkConfiguration); | ||
const collectionPageSize = 999; | ||
|
||
expect(webSdkConfiguration.getCollectionPageSize()).to.be.equal(25); | ||
webSdkConfiguration.setCollectionPageSize(collectionPageSize); | ||
expect(webSdkConfiguration.getCollectionPageSize()).to.be.equal(collectionPageSize); | ||
}); | ||
}); |