| 1 |
import Helper, { states } from "./_helper"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | Has Many | Named | accessor", () => { |
| 4 |
let helper; |
| 5 |
beforeEach(() => { |
| 6 |
helper = new Helper(); |
| 7 |
}); |
| 8 |
afterEach(() => { |
| 9 |
helper.shutdown(); |
| 10 |
}); |
| 11 |
|
| 12 |
/* |
| 13 |
The reference to a belongs-to association is correct, for all states |
| 14 |
*/ |
| 15 |
states.forEach((state) => { |
| 16 |
test(`the references of a ${state} are correct`, () => { |
| 17 |
let [user, posts] = helper[state](); |
| 18 |
|
| 19 |
expect(user.blogPosts.models).toHaveLength(posts.length); |
| 20 |
expect(user.blogPostIds).toHaveLength(posts.length); |
| 21 |
|
| 22 |
posts.forEach((post, i) => { |
| 23 |
expect(user.blogPosts.models[i]).toEqual(posts[i]); |
| 24 |
|
| 25 |
if (post.isSaved()) { |
| 26 |
expect(user.blogPostIds.indexOf(post.id) > -1).toBeTruthy(); |
| 27 |
} |
| 28 |
}); |
| 29 |
}); |
| 30 |
}); |
| 31 |
}); |