| 1 |
import Helper, { states } from "./_helper"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | Mixed | One To Many | 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.posts.models).toHaveLength(posts.length); |
| 20 |
expect(user.postIds).toHaveLength(posts.length); |
| 21 |
|
| 22 |
posts.forEach((post) => { |
| 23 |
expect(user.posts.includes(post)).toBeTruthy(); |
| 24 |
|
| 25 |
if (post.isSaved()) { |
| 26 |
expect(user.postIds.indexOf(post.id) > -1).toBeTruthy(); |
| 27 |
} |
| 28 |
|
| 29 |
// Check the inverse |
| 30 |
expect(post.user.attrs).toEqual(user.attrs); |
| 31 |
expect(post.userId).toEqual(user.id); |
| 32 |
}); |
| 33 |
}); |
| 34 |
}); |
| 35 |
}); |