Skip to content

Commit 0c3ea65

Browse files
committed
fix parse test
1 parent 831f0b8 commit 0c3ea65

File tree

1 file changed

+4
-65
lines changed

1 file changed

+4
-65
lines changed

browser/lib/src/parse.test.ts

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { JSONADParser } from './parse.js';
44
const EXAMPLE_SUBJECT = 'http://example.com/1';
55
const EXAMPLE_SUBJECT2 = 'http://example.com/2';
66
const EXAMPLE_SUBJECT3 = 'http://example.com/3';
7-
const EXAMPLE_SUBJECT4 = 'http://example.com/4';
87

98
const STRING_PROPERTY = 'http://example.com/some-string-property';
109
const NUMBER_PROPERTY = 'http://example.com/some-number-property';
@@ -21,71 +20,13 @@ describe('parse.ts', () => {
2120
};
2221

2322
const parser = new JSONADParser();
24-
const [resource] = parser.parseObject(jsonObject);
23+
const [resource] = parser.parse(jsonObject);
2524

2625
expect(resource.get(STRING_PROPERTY)).toBe('Hoi');
2726
expect(resource.get(NUMBER_PROPERTY)).toBe(10);
2827
expect(resource.get(BOOLEAN_PROPERTY)).toBe(true);
2928
});
3029

31-
it('parses a JSON-AD object with a nested resource', ({ expect }) => {
32-
const jsonObjectWithID = {
33-
'@id': EXAMPLE_SUBJECT,
34-
[NESTED_RESOURCE_PROPERTY]: {
35-
'@id': EXAMPLE_SUBJECT2,
36-
[STRING_PROPERTY]: 'Hoi',
37-
},
38-
};
39-
40-
const jsonObjectWithoutID = {
41-
'@id': EXAMPLE_SUBJECT,
42-
[NESTED_RESOURCE_PROPERTY]: {
43-
[STRING_PROPERTY]: 'Hoi',
44-
},
45-
};
46-
47-
const jsonWithArrayOfResources = {
48-
'@id': EXAMPLE_SUBJECT,
49-
[NESTED_RESOURCE_PROPERTY]: [
50-
{
51-
'@id': EXAMPLE_SUBJECT2,
52-
[STRING_PROPERTY]: 'Hoi',
53-
},
54-
EXAMPLE_SUBJECT3,
55-
{
56-
[STRING_PROPERTY]: 'Hoi',
57-
},
58-
],
59-
};
60-
61-
const parser = new JSONADParser();
62-
const [resource1, parsedResources1] = parser.parseObject(jsonObjectWithID);
63-
expect(resource1.get(NESTED_RESOURCE_PROPERTY)).toBe(EXAMPLE_SUBJECT2);
64-
expect(parsedResources1).toHaveLength(2);
65-
expect(parsedResources1[1].get(STRING_PROPERTY)).toBe('Hoi');
66-
67-
const [resource2, parsedResources2] =
68-
parser.parseObject(jsonObjectWithoutID);
69-
70-
expect(resource2.get(NESTED_RESOURCE_PROPERTY)).toEqual({
71-
[STRING_PROPERTY]: 'Hoi',
72-
});
73-
74-
expect(parsedResources2).toHaveLength(1);
75-
76-
const [resource3, parsedResources3] = parser.parseObject(
77-
jsonWithArrayOfResources,
78-
);
79-
80-
expect(resource3.get(NESTED_RESOURCE_PROPERTY)).toEqual([
81-
EXAMPLE_SUBJECT2,
82-
EXAMPLE_SUBJECT3,
83-
{ [STRING_PROPERTY]: 'Hoi' },
84-
]);
85-
86-
expect(parsedResources3).toHaveLength(2);
87-
});
88-
8930
it('parses an array of jsonObjects', ({ expect }) => {
9031
const array = [
9132
{
@@ -100,17 +41,15 @@ describe('parse.ts', () => {
10041
'@id': EXAMPLE_SUBJECT3,
10142
[STRING_PROPERTY]: 'Third Resource',
10243
[NESTED_RESOURCE_PROPERTY]: {
103-
'@id': EXAMPLE_SUBJECT4,
104-
[STRING_PROPERTY]: 'Fourth Resource',
44+
[STRING_PROPERTY]: 'Nested Resource',
10545
},
10646
},
10747
];
10848

10949
const parser = new JSONADParser();
110-
const [resources, parsedResources] = parser.parseArray(array);
50+
const resources = parser.parse(array);
11151

11252
expect(resources).toHaveLength(3);
113-
expect(parsedResources).toHaveLength(4);
11453
});
11554

11655
it('Handles resources without an ID', ({ expect }) => {
@@ -119,7 +58,7 @@ describe('parse.ts', () => {
11958
};
12059

12160
const parser = new JSONADParser();
122-
const [resource] = parser.parseObject(jsonObject, 'my-new-id');
61+
const [resource] = parser.parse(jsonObject, 'my-new-id');
12362

12463
expect(resource.get(STRING_PROPERTY)).toBe('Hoi');
12564
expect(resource.subject).toBe('my-new-id');

0 commit comments

Comments
 (0)