Skip to content

Commit a65f91b

Browse files
committed
test (model): test if relations are applied if any is null
1 parent e8b71a0 commit a65f91b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/model.test.js

+32
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,38 @@ describe('Model methods', () => {
115115
})
116116
})
117117

118+
test("find() method returns a object as instance of such Model with empty relationships", async () => {
119+
const _postResponse = postResponse;
120+
_postResponse.user = null;
121+
_postResponse.relationships.tags = [];
122+
123+
axiosMock.onGet("http://localhost/posts/1").reply(200, _postResponse);
124+
125+
const post = await Post.find(1);
126+
127+
expect(post).toEqual(postResponse);
128+
expect(post).toBeInstanceOf(Post);
129+
expect(post.user).toStrictEqual(null);
130+
expect(post.relationships.tags).toStrictEqual([]);
131+
});
132+
133+
test("find() method returns a object as instance of such Model with some empty relationships", async () => {
134+
const _postResponse = postResponse;
135+
_postResponse.user = null;
136+
137+
axiosMock.onGet("http://localhost/posts/1").reply(200, _postResponse);
138+
139+
const post = await Post.find(1);
140+
141+
expect(post).toEqual(postResponse);
142+
expect(post).toBeInstanceOf(Post);
143+
expect(post.user).toStrictEqual(null);
144+
145+
post.relationships.tags.forEach((tag) => {
146+
expect(tag).toBeInstanceOf(Tag);
147+
});
148+
});
149+
118150
test('get() method returns a array of objects as instance of suchModel', async () => {
119151
axiosMock.onGet('http://localhost/posts').reply(200, postsResponse)
120152

0 commit comments

Comments
 (0)