Skip to content

Commit

Permalink
fix: extraClientMetadata.properties keys do not get transformed
Browse files Browse the repository at this point in the history
BREAKING CHANGE: custom client metadata properties will not get
transformed between snake_case and camelCase anymore to allow for
namespaced metadata properties such as `custom://metadata`
  • Loading branch information
panva committed Sep 26, 2018
1 parent ab64268 commit 837beca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/helpers/client_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ module.exports = function getSchema(provider) {
DEFAULT.web_message_uris = [];
}

instance(provider).RECOGNIZED_METADATA = RECOGNIZED_METADATA;

const ENUM = {
...ENUMS,
default_acr_values: () => configuration.acrValues,
Expand Down
17 changes: 15 additions & 2 deletions lib/models/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ module.exports = function getClient(provider) {
async function schemaValidate(client, metadata) {
const schema = new Schema(metadata);

Object.assign(client, _.mapKeys(schema, (value, key) => _.camelCase(key)));
Object.assign(client, _.mapKeys(schema, (value, key) => {
if (!instance(provider).RECOGNIZED_METADATA.includes(key)) {
return key;
}

return _.camelCase(key);
}));

return client;
}
Expand Down Expand Up @@ -340,7 +346,14 @@ module.exports = function getClient(provider) {
}

metadata() {
return _.mapKeys(this, (value, key) => _.snakeCase(key));
return _.mapKeys(this, (value, key) => {
const snaked = _.snakeCase(key);
if (!instance(provider).RECOGNIZED_METADATA.includes(snaked)) {
return key;
}

return snaked;
});
}

get sectorIdentifier() {
Expand Down
5 changes: 3 additions & 2 deletions test/configuration/custom_client_metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ describe('extraClientMetadata configuration', () => {
expect(calls[5].calledWith('foo_bar', 'three')).to.be.true;

const client = await provider.Client.find('client-2');
expect(client).to.have.property('fooBar');
expect(client).to.have.property('foo_bar');
expect(client.metadata()).to.have.property('foo_bar');
});

it('can be used assign standard properties depending on the value of a custom one', async () => {
it('can be used to assign standard properties depending on the value of a custom one', async () => {
const provider = new Provider('http://localhost:3000', {
extraClientMetadata: {
properties: ['foo'],
Expand Down

0 comments on commit 837beca

Please sign in to comment.