Skip to content

Commit ff0bbd2

Browse files
committed
test/template_provider: Test loading sub-templates
1 parent fb6b327 commit ff0bbd2

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

test/template_provider.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ function runSharedTests(createProvider) {
4848
return provider.list()
4949
.then((tmplList) => {
5050
assert.deepStrictEqual(tmplList.sort(), [
51+
'test/base',
5152
'test/combine',
5253
'test/complex',
54+
'test/extended',
5355
'test/simple',
5456
'test/simple_udp'
5557
]);
@@ -86,11 +88,21 @@ function runSharedTests(createProvider) {
8688
return provider.fetch('test/simple')
8789
.then((tmpl) => {
8890
assert.ok(tmpl);
89-
console.log(JSON.stringify(tmpl, null, 3));
91+
console.log(JSON.stringify(tmpl, null, 2));
9092
assert.strictEqual(tmpl.title, 'Simple YAML file');
9193
assert.strictEqual(tmpl.target, 'as3');
9294
});
9395
});
96+
it('load_sub_template', function () {
97+
const provider = createProvider();
98+
return provider.fetch('test/extended')
99+
.then((tmpl) => {
100+
assert.ok(tmpl);
101+
console.log(JSON.stringify(tmpl, null, 2));
102+
assert.strictEqual(tmpl.title, 'Main template');
103+
assert.strictEqual(tmpl._allOf[0].title, 'Base Template');
104+
});
105+
});
94106
it('load_single_bad', function () {
95107
const provider = createProvider();
96108
return assert.isRejected(provider.fetch('does_not_exist'));
@@ -114,11 +126,11 @@ function runSharedTests(createProvider) {
114126
const provider = createProvider();
115127
return assert.becomes(provider.getNumTemplateSourceTypes('test'), {
116128
MST: 1,
117-
YAML: 3
129+
YAML: 5
118130
})
119131
.then(() => assert.becomes(provider.getNumTemplateSourceTypes(), {
120132
MST: 1,
121-
YAML: 3
133+
YAML: 5
122134
}));
123135
});
124136
it('num_schemas', function () {
@@ -147,13 +159,17 @@ function runSharedTests(createProvider) {
147159

148160
const tmplNames = setData.templates.map(x => x.name).sort();
149161
assert.deepStrictEqual(tmplNames, [
162+
'test/base',
150163
'test/combine',
151164
'test/complex',
165+
'test/extended',
152166
'test/simple',
153167
'test/simple_udp'
154168
]);
155169
const tmplDesc = setData.templates.map(x => x.description).sort();
156170
assert.deepStrictEqual(tmplDesc, [
171+
'',
172+
'',
157173
'',
158174
'A simple template to test we can handle the .yaml file extension',
159175
'An example of how to combine templates',

test/templatesets/test/base.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
title: Base Template
2+
contentType: application/json
3+
definitions:
4+
name:
5+
title: Object Name
6+
description: Give this thing a great name!
7+
minLength: 1
8+
description:
9+
title: Object Description
10+
description: What is this object about? (can be empty)
11+
number:
12+
title: Number please!
13+
description: A number would be grand, but please be positive.
14+
minimum: 0
15+
template: |
16+
{
17+
"name": "{{name}}",
18+
"description": "{{description}}",
19+
"integer": {{number::integer}},
20+
"port": {{port:types:port}}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
title: Main template
2+
contentType: application/json
3+
allOf:
4+
- $ref: "base.yaml#"
5+
definitions:
6+
extraData:
7+
title: Something Extra
8+
description: This is in addition to the base template
9+
template: |
10+
{
11+
"extraData": "{{extraData}}"
12+
}

0 commit comments

Comments
 (0)