| 1 |
import Helper, { states } from "./_helper"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | Belongs To | One To One | association #new", () => { |
| 4 |
let helper; |
| 5 |
beforeEach(() => { |
| 6 |
helper = new Helper(); |
| 7 |
}); |
| 8 |
afterEach(() => { |
| 9 |
helper.shutdown(); |
| 10 |
}); |
| 11 |
|
| 12 |
/* |
| 13 |
The model can make a new unsaved belongs-to association, for all states |
| 14 |
*/ |
| 15 |
|
| 16 |
states.forEach((state) => { |
| 17 |
test(`a ${state} can build a new associated parent`, () => { |
| 18 |
let [user] = helper[state](); |
| 19 |
|
| 20 |
let profile = user.newProfile({ age: 300 }); |
| 21 |
|
| 22 |
expect(!profile.id).toBeTruthy(); |
| 23 |
expect(user.profile).toEqual(profile); |
| 24 |
expect(user.profileId).toBeNil(); |
| 25 |
expect(profile.user).toEqual(user); |
| 26 |
expect(profile.userId).toEqual(user.id); |
| 27 |
|
| 28 |
user.save(); |
| 29 |
|
| 30 |
expect(profile.id).toBeTruthy(); |
| 31 |
expect(user.profileId).toEqual(profile.id); |
| 32 |
}); |
| 33 |
}); |
| 34 |
}); |