| 1 |
import Helper, { states } from "./_helper"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | Has Many | Basic | association #create", () => { |
| 4 |
let helper; |
| 5 |
beforeEach(() => { |
| 6 |
helper = new Helper(); |
| 7 |
}); |
| 8 |
afterEach(() => { |
| 9 |
helper.shutdown(); |
| 10 |
}); |
| 11 |
|
| 12 |
/* |
| 13 |
The model can create a has-many association, for all states |
| 14 |
*/ |
| 15 |
states.forEach((state) => { |
| 16 |
test(`a ${state} can create an associated parent`, () => { |
| 17 |
let [user] = helper[state](); |
| 18 |
let initialCount = user.posts.models.length; |
| 19 |
|
| 20 |
let post = user.createPost({ title: "Lorem ipsum" }); |
| 21 |
|
| 22 |
expect(post.id).toBeTruthy(); |
| 23 |
expect(user.posts.models).toHaveLength(initialCount + 1); |
| 24 |
expect(user.posts.includes(post)).toBeTruthy(); |
| 25 |
expect(user.postIds.indexOf(post.id) > -1).toBeTruthy(); |
| 26 |
expect(user.attrs.postIds.indexOf(post.id) > -1).toBeTruthy(); |
| 27 |
}); |
| 28 |
}); |
| 29 |
}); |