| 1 |
import Helper, { states } from "./_helper"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | Has Many | One-Way Reflexive | 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 child`, () => { |
| 18 |
let [tag] = helper[state](); |
| 19 |
let initialCount = tag.tags.models.length; |
| 20 |
|
| 21 |
let blueTag = tag.newTag({ name: "Blue" }); |
| 22 |
|
| 23 |
expect(!blueTag.id).toBeTruthy(); |
| 24 |
expect(tag.tags.models).toHaveLength(initialCount + 1); |
| 25 |
expect(blueTag.tags.models).toHaveLength(0); |
| 26 |
|
| 27 |
blueTag.save(); |
| 28 |
|
| 29 |
expect(blueTag.attrs).toEqual({ |
| 30 |
id: blueTag.id, |
| 31 |
name: "Blue", |
| 32 |
tagIds: [], |
| 33 |
}); |
| 34 |
expect(tag.tags.models).toHaveLength(initialCount + 1); |
| 35 |
expect(tag.tags.includes(blueTag)).toBeTruthy(); |
| 36 |
expect(tag.tagIds.indexOf(blueTag.id) > -1).toBeTruthy(); |
| 37 |
expect(blueTag.tags.includes(tag)).toBeFalsy(); |
| 38 |
}); |
| 39 |
}); |
| 40 |
}); |