| 1 |
import Helper, { states } from "./_helper"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | Mixed | Many To One | 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 [post, user] = helper[state](); |
| 18 |
|
| 19 |
if (post.user) { |
| 20 |
expect(post.user.equals(user)).toBeTruthy(); |
| 21 |
} else { |
| 22 |
expect(post.user).toBeNull(); |
| 23 |
expect(user).toBeNull(); |
| 24 |
} |
| 25 |
expect(post.userId).toEqual(user ? user.id : null); |
| 26 |
|
| 27 |
post.save(); |
| 28 |
|
| 29 |
// Check the inverse |
| 30 |
if (user && user.isSaved()) { |
| 31 |
user.reload(); |
| 32 |
expect(user.posts.includes(post)).toBeTruthy(); |
| 33 |
} |
| 34 |
}); |
| 35 |
}); |
| 36 |
}); |