Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Add subdomain field support to CLI apps #26

Merged
merged 3 commits into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/build/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ Key | Required | Type | Description
`dict` | no | `boolean` | Is this field a key/value input?
`computed` | no | `boolean` | Is this field automatically populated (and hidden from the user)?
`altersDynamicFields` | no | `boolean` | Does the value of this field affect the definitions of other fields in the set?
`inputFormat` | no | `string` | Useful when you expect the input to be part of a longer string. Put "{{input}}" in place of the user's input (IE: "https://{{input}}.yourdomain.com").

-----

Expand Down
5 changes: 5 additions & 0 deletions exported-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
"altersDynamicFields": {
"description": "Does the value of this field affect the definitions of other fields in the set?",
"type": "boolean"
},
"inputFormat": {
"description": "Useful when you expect the input to be part of a longer string. Put \"{{input}}\" in place of the user's input (IE: \"https://{{input}}.yourdomain.com\").",
"type": "string",
"pattern": "^.*{{input}}.*$"
}
},
"additionalProperties": false
Expand Down
6 changes: 6 additions & 0 deletions lib/schemas/FieldSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ module.exports = makeSchema({
description: 'Does the value of this field affect the definitions of other fields in the set?',
type: 'boolean',
},
inputFormat: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should remove the , from the inputFormat value (because while it simplifies for the backend, there's no real justification for it in this "public-facing" place. It's arguably cleaner if it was just https://{{subdomain}}.yourdomain.com/, and since it applies to subdomain only, should this field name be subdomainFormat instead of inputFormat?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that inputFormat could do more than just subdomain, so I've changed the description to be more general.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

description: 'Useful when you expect the input to be part of a longer string. Put "{{input}}" in place of the user\'s input (IE: "https://{{input}}.yourdomain.com").',
type: 'string',
// TODO: Check if it contains one and ONLY ONE '{{input}}'
pattern: '^.*\{\{input\}\}.*$'
},
},
additionalProperties: false,
}, [
Expand Down
44 changes: 44 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,50 @@ describe('app', () => {
results.errors[1].stack.should.eql('instance.searchOrCreates.fooSearchOrCreate.search must match a "key" from a search (options: fooSearch)');
results.errors[2].stack.should.eql('instance.searchOrCreates.fooSearchOrCreate.create must match a "key" from a create (options: fooCreate)');
});

it('should validate inputFormat', () => {
const appCopy = copy(appDefinition);
appCopy.authentication = {
type: 'custom',
test: {
url: 'https://example.com',
},
fields: [
{
key: 'subdomain',
type: 'string',
required: true,
inputFormat: 'https://{{input}}.example.com',
},
],
};
const results = schema.validateAppDefinition(appCopy);
results.errors.should.eql([]);
});

it('should invalidate illegal inputFormat', () => {
const appCopy = copy(appDefinition);
appCopy.authentication = {
type: 'custom',
test: {
url: 'https://example.com',
},
fields: [
{
key: 'subdomain',
type: 'string',
required: true,
inputFormat: 'https://{{input}.example.com',
},
],
};
const results = schema.validateAppDefinition(appCopy);
results.errors.length.should.eql(1);

const error = results.errors[0];
error.name.should.eql('pattern');
error.instance.should.eql('https://{{input}.example.com');
});
});

describe('export', () => {
Expand Down