| 1 |
import Helper, { states } from "./_helper"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | Belongs To | Named Reflexive Explicit Inverse | association #set", () => { |
| 4 |
let helper; |
| 5 |
beforeEach(() => { |
| 6 |
helper = new Helper(); |
| 7 |
}); |
| 8 |
afterEach(() => { |
| 9 |
helper.shutdown(); |
| 10 |
}); |
| 11 |
|
| 12 |
/* |
| 13 |
The model can update its association via parent, for all states |
| 14 |
*/ |
| 15 |
states.forEach((state) => { |
| 16 |
test(`a ${state} can update its association to a saved parent`, () => { |
| 17 |
let [user] = helper[state](); |
| 18 |
let friend = helper.savedParent(); |
| 19 |
|
| 20 |
user.bestFriend = friend; |
| 21 |
|
| 22 |
expect(user.bestFriendId).toEqual(friend.id); |
| 23 |
expect(user.bestFriend.attrs).toEqual(friend.attrs); |
| 24 |
}); |
| 25 |
|
| 26 |
test(`a ${state} can update its association to a new parent`, () => { |
| 27 |
let [user] = helper[state](); |
| 28 |
let friend = helper.newParent(); |
| 29 |
|
| 30 |
user.bestFriend = friend; |
| 31 |
|
| 32 |
expect(user.bestFriendId).toBeNil(); |
| 33 |
expect(user.bestFriend.attrs).toEqual(friend.attrs); |
| 34 |
}); |
| 35 |
|
| 36 |
test(`a ${state} can update its association to a null parent`, () => { |
| 37 |
let [user] = helper[state](); |
| 38 |
|
| 39 |
user.bestFriend = null; |
| 40 |
|
| 41 |
expect(user.bestFriendId).toBeNil(); |
| 42 |
expect(user.bestFriend).toBeNil(); |
| 43 |
}); |
| 44 |
}); |
| 45 |
}); |