Skip to content

Commit

Permalink
feat(): expand after create (#76)
Browse files Browse the repository at this point in the history
* feat(): make 'with' work with .create
  • Loading branch information
mkucharz authored Jan 16, 2018
1 parent 9276fe1 commit 0764e1b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/lib-js-core/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ class Data extends QueryBuilder {
}

return this.fetch(fetchObject.url, fetchObject, headers)
.then(this.resolveRelatedModels.bind(this))
.then(this._replaceCustomTypesWithValue.bind(this))
.then(this._mapFields.bind(this))
}
Expand Down
23 changes: 17 additions & 6 deletions packages/lib-js-core/test/e2e/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('Data', function () {
})

describe('#with()', () => {
it('should extend reference with object', () =>
it('should expand reference with object', () =>
users
.create({username: 'John', password: 'test'})
.then(user =>
Expand All @@ -253,19 +253,30 @@ describe('Data', function () {
.should.eventually.have.nested.property('author.username', 'john')
}))

it('should extend reference with object after update', async () => {
const user = await users.create({username: 'john1', password: 'test'})
it('should expand reference with object after update', async () => {
const username = getRandomString()
const user = await users.create({username, password: 'test'})
const obj = await run()
.with('author')
.create({field_string: 'with author', author: user.id})

await run()
.with('author')
.update(obj.id, {field_string: 'with author'})
.should.eventually.have.nested.property('author.username', 'john1')
.should.eventually.have.nested.property('author.username', username)
})

it('should expand reference with object after create', async () => {
const username = getRandomString()
const user = await users.create({username, password: 'test'})

await run()
.with('author')
.create({field_string: 'with author', author: user.id})
.should.eventually.have.nested.property('author.username', username)
})

it('should extend relation with array of objects', async () => {
it('should expand relation with array of objects', async () => {
const usersList = await users
.create([
{username: 'lou', password: 'test'},
Expand All @@ -286,7 +297,7 @@ describe('Data', function () {
)
})

it('should throw error when extended field has no target', async () => {
it('should throw error when expanded field has no target', async () => {
await run().create({field_string: 'example-string1'})

run()
Expand Down

0 comments on commit 0764e1b

Please sign in to comment.