Skip to content

Commit e51d42f

Browse files
author
Samuel Guirado Navarro
committed
Add unit test to that showcases Issue whitlockjc#154
1 parent c2207b6 commit e51d42f

File tree

2 files changed

+52
-17
lines changed

2 files changed

+52
-17
lines changed

test/browser/documents/nested/test-nested.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ local:
55
$ref: '#/name'
66
missing:
77
$ref: '#/some/missing/path'
8+
remote:
9+
$ref: 'https://rawgit.com/whitlockjc/json-refs/master/package.json'

test/test-json-refs.js

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -264,22 +264,7 @@ describe('json-refs API', function () {
264264
name: testTypesDocument.definitions.String
265265
}
266266
};
267-
var expectedRelativeValue = {
268-
name: testNestedDocument.name,
269-
child: {
270-
name: testNestedDocument1.name,
271-
ancestor: {
272-
name: testDocument1.name,
273-
nested: testDocument1.nested,
274-
local: testDocument1.name,
275-
missing: testDocument1.missing
276-
},
277-
local: testNestedDocument1.name,
278-
missing: testNestedDocument1.missing
279-
},
280-
local: testNestedDocument.name,
281-
missing: testNestedDocument.missing
282-
};
267+
var expectedRelativeValue;
283268
var expectedValidResolveRefs;
284269
var expectedFullyResolved;
285270
var remotePkgJson;
@@ -288,6 +273,23 @@ describe('json-refs API', function () {
288273
JsonRefs.findRefsAt('https://rawgit.com/whitlockjc/json-refs/master/package.json')
289274
.then(function (refs) {
290275
remotePkgJson = refs.value;
276+
expectedRelativeValue = {
277+
name: testNestedDocument.name,
278+
child: {
279+
name: testNestedDocument1.name,
280+
ancestor: {
281+
name: testDocument1.name,
282+
nested: testDocument1.nested,
283+
local: testDocument1.name,
284+
missing: testDocument1.missing
285+
},
286+
local: testNestedDocument1.name,
287+
missing: testNestedDocument1.missing
288+
},
289+
local: testNestedDocument.name,
290+
missing: testNestedDocument.missing,
291+
remote: remotePkgJson
292+
};
291293
expectedValidResolveRefs = {
292294
'#/local': {
293295
def: testDocument.local,
@@ -527,6 +529,14 @@ describe('json-refs API', function () {
527529
error: new Error('JSON Pointer points to missing location: #/some/missing/path'),
528530
missing: true
529531
},
532+
'#/remote/relative/remote': {
533+
def: testNestedDocument.remote,
534+
fqURI: testNestedDocument.remote.$ref,
535+
uri: testNestedDocument.remote.$ref,
536+
uriDetails: URI.parse(testNestedDocument.remote.$ref),
537+
type: 'remote',
538+
value: expectedRelativeValue.remote
539+
},
530540
'#/definitions/Person/properties/name': {
531541
def: testDocument.definitions.Person.properties.name,
532542
fqURI: testDocument.definitions.Person.properties.name.$ref,
@@ -1349,7 +1359,8 @@ describe('json-refs API', function () {
13491359
name: testNestedDocument.name,
13501360
child: expectedRelativeValue.child,
13511361
local: testNestedDocument.name,
1352-
missing: testNestedDocument.missing
1362+
missing: testNestedDocument.missing,
1363+
remote: expectedRelativeValue.remote
13531364
},
13541365
},
13551366
'#/remote/relative/child': {
@@ -1427,6 +1438,14 @@ describe('json-refs API', function () {
14271438
type: 'local',
14281439
error: new Error('JSON Pointer points to missing location: #/some/missing/path'),
14291440
missing: true
1441+
},
1442+
'#/remote/relative/remote': {
1443+
def: testNestedDocument.remote,
1444+
fqURI: testNestedDocument.remote.$ref,
1445+
uri: testNestedDocument.remote.$ref,
1446+
uriDetails: URI.parse(testNestedDocument.remote.$ref),
1447+
type: 'remote',
1448+
value: expectedRelativeValue.remote
14301449
}
14311450
});
14321451
})
@@ -1542,6 +1561,20 @@ describe('json-refs API', function () {
15421561
});
15431562

15441563
describe('issues', function () {
1564+
describe('Issue #154', function () {
1565+
it('should not resolve remote references contained by relative references when options.filter does not indicate it', function (done) {
1566+
JsonRefs.resolveRefs(testDocument, {
1567+
filter: ['relative'],
1568+
loaderOptions: {
1569+
processContent: yamlContentProcessor
1570+
},
1571+
location: testDocumentLocation
1572+
}).then(function (res) {
1573+
assert.deepEqual(res.resolved.remote.relative.remote, testNestedDocument.remote);
1574+
})
1575+
.then(done, done);
1576+
});
1577+
});
15451578
describe('Issue #135', function () {
15461579
it('should handle multi-document circular references', function (done) {
15471580
JsonRefs.resolveRefsAt(path.join(typeof window === 'undefined' ?

0 commit comments

Comments
 (0)