-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add overrides for headers when baseConfig contains immutable k…
…eys (#1511)
- Loading branch information
1 parent
d8fe557
commit fb676f2
Showing
5 changed files
with
190 additions
and
13 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
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,87 @@ | ||
import { | ||
Environment, | ||
ImmutableConfiguration, | ||
KeyHeaders, | ||
addKeysToHeadersOverride, | ||
} from './index'; | ||
|
||
describe('Key header override', () => { | ||
const apiKey = 'testKey'; | ||
const publishableKey = 'testPublishableKey'; | ||
const rateLimitingKey = 'testRateLimitKey'; | ||
|
||
it('should return passed in override if no base config is present', () => { | ||
const overrides = { | ||
headers: { | ||
testHeader: 'test', | ||
}, | ||
}; | ||
|
||
const result = addKeysToHeadersOverride(undefined, overrides); | ||
expect(result).toEqual(overrides); | ||
}); | ||
|
||
it('should return passed in override if no keys are present', () => { | ||
const baseConfig = new ImmutableConfiguration({ | ||
environment: Environment.SANDBOX, | ||
}); | ||
const overrides = { | ||
headers: { | ||
testHeader: 'test', | ||
}, | ||
}; | ||
|
||
const result = addKeysToHeadersOverride(baseConfig, overrides); | ||
expect(result).toEqual(overrides); | ||
}); | ||
|
||
it('Should append headers to override', () => { | ||
const baseConfig = new ImmutableConfiguration({ | ||
environment: Environment.SANDBOX, | ||
apiKey, | ||
rateLimitingKey, | ||
publishableKey, | ||
}); | ||
|
||
const overrides = { | ||
headers: { | ||
[KeyHeaders.API_KEY]: apiKey, | ||
[KeyHeaders.RATE_LIMITING_KEY]: rateLimitingKey, | ||
[KeyHeaders.PUBLISHABLE_KEY]: publishableKey, | ||
}, | ||
}; | ||
|
||
const result = addKeysToHeadersOverride(baseConfig, overrides); | ||
expect(result).toEqual(overrides); | ||
}); | ||
|
||
it('Should merge headers with existing overrides, with user overrides taking precedence', () => { | ||
const baseConfig = new ImmutableConfiguration({ | ||
environment: Environment.SANDBOX, | ||
apiKey, | ||
rateLimitingKey, | ||
publishableKey, | ||
}); | ||
|
||
const overrides = { | ||
headers: { | ||
[KeyHeaders.API_KEY]: 'userOverriddenApiKey', | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
'new-header': 'test', | ||
}, | ||
}; | ||
const expectedOverrides = { | ||
headers: { | ||
[KeyHeaders.API_KEY]: 'userOverriddenApiKey', | ||
[KeyHeaders.RATE_LIMITING_KEY]: rateLimitingKey, | ||
[KeyHeaders.PUBLISHABLE_KEY]: publishableKey, | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
'new-header': 'test', | ||
}, | ||
}; | ||
|
||
const result = addKeysToHeadersOverride(baseConfig, overrides); | ||
|
||
expect(result).toEqual(expectedOverrides); | ||
}); | ||
}); |
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