Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-data-adapter-tests

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-data-adapter-tests - npm Package Compare versions

Comparing version 2.0.0-alpha.6 to 2.0.0-alpha.7

4

CHANGELOG.md

@@ -0,1 +1,5 @@

##### 2.0.0-alpha.7 - 26 February 2016
- Improved testing
##### 2.0.0-alpha.6 - 23 February 2016

@@ -2,0 +6,0 @@

2

package.json

@@ -5,3 +5,3 @@ {

"homepage": "https://github.com/js-data/js-data-adapter-tests",
"version": "2.0.0-alpha.6",
"version": "2.0.0-alpha.7",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -12,18 +12,19 @@ /* global assert:true */

assert.debug('create', props)
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
const userId = user[User.idAttribute]
assert.debug('created', User.name, user)
assert.equal(user.name, props.name, `name of user should be "${props.name}"`)
assert.isDefined(user[User.idAttribute], 'new user should have an id')
assert.equal(user.name, props.name, 'user.name')
assert.isDefined(user[User.idAttribute], 'user[User.idAttribute]')
assert.debug('find', user[User.idAttribute])
const foundUser = await adapter.find(User, user[User.idAttribute])
assert.debug('found', JSON.stringify(foundUser, null, 2))
assert.debug('find', User.name, userId)
const foundUser = await adapter.find(User, userId)
assert.debug('found', User.name, foundUser)
assert.equal(foundUser.name, props.name, `name of user should be "${props.name}"`)
assert.isDefined(foundUser[User.idAttribute], 'new user should have an id')
assert.equal(foundUser[User.idAttribute], user[User.idAttribute])
assert.equal(foundUser.name, props.name, 'foundUser.name')
assert.isDefined(foundUser[User.idAttribute], 'foundUser[User.idAttribute]')
assert.equal(foundUser[User.idAttribute], userId, 'foundUser[User.idAttribute]')
})
})
}

@@ -12,5 +12,6 @@ /* global assert:true */

assert.debug('create', props)
assert.debug('create', User.name, props)
let user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
let userId = user[User.idAttribute]
assert.debug('created', User.name, user)

@@ -35,9 +36,47 @@ let beforeDestroyCalled = false

// Test re-assignment
return Promise.resolve()
}
assert.debug('destroy', User.name, userId)
const destroyedUser = await adapter.destroy(User, userId)
assert.debug('destroyed', User.name, destroyedUser)
assert.isUndefined(destroyedUser, 'destroyedUser')
assert.isTrue(beforeDestroyCalled, 'beforeDestroy should have been called')
assert.isTrue(afterDestroyCalled, 'afterDestroy should have been called')
})
it('should destroy a user and allow afterDestroy re-assignment', async function () {
const adapter = this.$$adapter
const User = this.$$User
const props = { name: 'John' }
assert.debug('create', User.name, props)
let user = await adapter.create(User, props)
let userId = user[User.idAttribute]
assert.debug('created', User.name, user)
let beforeDestroyCalled = false
let afterDestroyCalled = false
// Test beforeDestroy and afterDestroy
adapter.beforeDestroy = function (mapper, id, opts) {
beforeDestroyCalled = true
assert.isObject(mapper, 'beforeDestroy should have received mapper argument')
assert.isDefined(id, 'beforeDestroy should have received id argument')
assert.isObject(opts, 'beforeDestroy should have received opts argument')
// Test re-assignment
return Promise.resolve()
}
adapter.afterDestroy = function (mapper, id, opts) {
afterDestroyCalled = true
assert.isObject(mapper, 'afterDestroy should have received mapper argument')
assert.isDefined(id, 'afterDestroy should have received id argument')
assert.isObject(opts, 'afterDestroy should have received opts argument')
// Test re-assignment
return Promise.resolve(1234)
}
assert.debug('destroy', user[User.idAttribute])
const destroyedUser = await adapter.destroy(User, user[User.idAttribute])
assert.debug('destroyed', JSON.stringify(destroyedUser, null, 2))
assert.equal(destroyedUser, 1234)
assert.debug('destroy', User.name, userId)
const destroyedUser = await adapter.destroy(User, userId)
assert.debug('destroyed', User.name, destroyedUser)
assert.equal(destroyedUser, 1234, 'destroyedUser')
assert.isTrue(beforeDestroyCalled, 'beforeDestroy should have been called')

@@ -51,13 +90,13 @@ assert.isTrue(afterDestroyCalled, 'afterDestroy should have been called')

assert.debug('create', props)
assert.debug('create', User.name, props)
let user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
let userId = user[User.idAttribute]
assert.debug('created', User.name, user)
assert.debug('destroy', user[User.idAttribute])
const result = await adapter.destroy(User, user[User.idAttribute], { raw: true })
assert.debug('destroyed', JSON.stringify(result, null, 2))
assert.isDefined(result.data, 'result.data is defined')
assert.isDefined(result.deleted, 'result.deleted is defined')
assert.equal(result.data, user[User.idAttribute], `result.data should be ${user[User.idAttribute]}`)
assert.equal(result.deleted, 1, 'result.deleted should be 1')
assert.debug('destroy', User.name, userId)
const result = await adapter.destroy(User, userId, { raw: true })
assert.debug('destroyed', User.name, result)
assert.isUndefined(result.data, 'result.data')
assert.isDefined(result.deleted, 'result.deleted')
assert.equal(result.deleted, 1, 'result.deleted')
})

@@ -68,6 +107,6 @@ it('should destroy nothing', async function () {

assert.debug('destroy', 'non-existent-id')
assert.debug('destroy', User.name, 'non-existent-id')
const result = await adapter.destroy(User, 'non-existent-id')
assert.debug('destroyed', JSON.stringify(result, null, 2))
assert.isUndefined(result, 'result should be undefined')
assert.debug('destroyed', User.name, result)
assert.isUndefined(result, 'result')
})

@@ -78,10 +117,25 @@ it('should destroy nothing and return raw', async function () {

assert.debug('destroy', 'non-existent-id')
assert.debug('destroy', User.name, 'non-existent-id')
const result = await adapter.destroy(User, 'non-existent-id', { raw: true })
assert.debug('destroyed', JSON.stringify(result, null, 2))
assert.isUndefined(result.data, 'result.data should be undefined')
assert.isDefined(result.deleted, 'result.deleted is defined')
assert.equal(result.deleted, 0, 'result.deleted should be 0')
assert.debug('destroyed', User.name, result)
assert.isUndefined(result.data, 'result.data')
assert.isDefined(result.deleted, 'result.deleted')
assert.equal(result.deleted, 0, 'result.deleted')
})
it('should destroy a user and return deleted id', async function () {
const adapter = this.$$adapter
const User = this.$$User
const props = { name: 'John' }
assert.debug('create', User.name, props)
let user = await adapter.create(User, props)
let userId = user[User.idAttribute]
assert.debug('created', User.name, user)
assert.debug('destroy', User.name, userId)
const destroyedUser = await adapter.destroy(User, userId, { returnDeletedIds: true })
assert.debug('destroyed', User.name, destroyedUser)
assert.equal(destroyedUser, userId, 'destroyedUser')
})
})
}

@@ -12,24 +12,107 @@ /* global assert:true */

assert.debug('create', props)
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
const userId = user[User.idAttribute]
assert.debug('created', User.name, user)
assert.debug('findAll', props)
assert.debug('create', User.name, { name: 'Sally' })
const user2 = await adapter.create(User, { name: 'Sally' })
assert.debug('created', User.name, user2)
assert.debug('findAll', User.name, props)
let foundUsers = await adapter.findAll(User, props)
assert.debug('found', JSON.stringify(foundUsers, null, 2))
assert.equal(foundUsers.length, 1)
assert.equal(foundUsers[0][User.idAttribute], user[User.idAttribute])
assert.equal(foundUsers[0].name, 'John')
assert.debug('found', User.name, foundUsers)
assert.equal(foundUsers.length, 1, 'foundUsers.length')
assert.equal(foundUsers[0][User.idAttribute], userId, 'foundUsers[0][User.idAttribute]')
assert.equal(foundUsers[0].name, 'John', 'foundUsers[0].name')
assert.debug('destroyAll', props)
assert.debug('destroyAll', User.name, props)
const destroyedUsers = await adapter.destroyAll(User, props)
assert.equal(destroyedUsers.length, 1)
assert.debug('destroyed', JSON.stringify(destroyedUsers, null, 2))
assert.debug('destroyed', User.name, destroyedUsers)
assert.isUndefined(destroyedUsers, 'destroyedUsers')
assert.debug('findAll', props)
assert.debug('findAll', User.name, props)
foundUsers = await adapter.findAll(User, props)
assert.debug('found', JSON.stringify(foundUsers, null, 2))
assert.debug('found', User.name, foundUsers)
assert.equal(foundUsers.length, 0)
assert.debug('findAll', User.name, {})
foundUsers = await adapter.findAll(User, {})
assert.debug('found', User.name, foundUsers)
assert.equal(foundUsers.length, 1)
})
it('should destroy users and return raw', async function () {
const adapter = this.$$adapter
const User = this.$$User
const props = { name: 'John' }
assert.debug('create', User.name, props)
let user = await adapter.create(User, props)
assert.debug('created', User.name, user)
assert.debug('destroyAll', User.name, props)
const result = await adapter.destroyAll(User, props, { raw: true })
assert.debug('destroyed', User.name, result)
assert.isUndefined(result.data, 'result.data')
assert.isDefined(result.deleted, 'result.deleted')
assert.equal(result.deleted, 1, 'result.deleted')
})
it('should destroy nothing', async function () {
const adapter = this.$$adapter
const User = this.$$User
assert.debug('destroyAll', User.name, {})
const result = await adapter.destroyAll(User, {})
assert.debug('destroyed', User.name, result)
assert.isUndefined(result, 'result')
})
it('should destroy nothing and return raw', async function () {
const adapter = this.$$adapter
const User = this.$$User
assert.debug('destroyAll', User.name, {})
const result = await adapter.destroyAll(User, {}, { raw: true })
assert.debug('destroyed', User.name, result)
assert.isUndefined(result.data, 'result.data')
assert.isDefined(result.deleted, 'result.deleted')
assert.equal(result.deleted, 0, 'result.deleted')
})
it('should optionally return ids', async function () {
const adapter = this.$$adapter
const User = this.$$User
const props = { name: 'John' }
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
const userId = user[User.idAttribute]
assert.debug('created', User.name, user)
assert.debug('create', User.name, { name: 'Sally' })
const user2 = await adapter.create(User, { name: 'Sally' })
assert.debug('created', User.name, user2)
assert.debug('findAll', User.name, props)
let foundUsers = await adapter.findAll(User, props)
assert.debug('found', User.name, foundUsers)
assert.equal(foundUsers.length, 1, 'foundUsers.length')
assert.equal(foundUsers[0][User.idAttribute], userId, 'foundUsers[0][User.idAttribute]')
assert.equal(foundUsers[0].name, 'John', 'foundUsers[0].name')
assert.debug('destroyAll', User.name, props)
const destroyedUsers = await adapter.destroyAll(User, props, { returnDeletedIds: true })
assert.debug('destroyed', User.name, destroyedUsers)
assert.equal(destroyedUsers.length, 1, 'destroyedUsers.length')
assert.deepEqual(destroyedUsers, [userId], 'destroyedUsers')
assert.debug('findAll', User.name, props)
foundUsers = await adapter.findAll(User, props)
assert.debug('found', User.name, foundUsers)
assert.equal(foundUsers.length, 0)
assert.debug('findAll', User.name, {})
foundUsers = await adapter.findAll(User, {})
assert.debug('found', User.name, foundUsers)
assert.equal(foundUsers.length, 1)
})
})
}

@@ -21,13 +21,17 @@ /* global assert:true */

let props = { name: 'John' }
assert.debug('create', props)
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
assert.debug('created', User.name, user)
const userId = user[User.idAttribute]
assert.equal(user.name, 'John', 'name of created user should be "John"')
assert.isDefined(user[User.idAttribute], 'created user should have an id')
assert.equal(user.name, 'John', 'user.name')
assert.isDefined(user[User.idAttribute], 'user[User.idAttribute]')
// Test beforeFind and afterFind
let beforeFindCalled = false
let afterFindCalled = false
adapter.beforeFind = function (mapper, id, opts) {
beforeFindCalled = true
assert.isObject(mapper, 'beforeFind should have received mapper argument')
assert.isDefined(id, 'beforeFind should have received id argument')
assert.equal(id, userId, 'beforeFind should have received correct id argument')
assert.isObject(opts, 'beforeFind should have received opts argument')

@@ -38,4 +42,6 @@ // Optionally return a promise for async

adapter.afterFind = function (mapper, id, opts, record) {
afterFindCalled = true
assert.isObject(mapper, 'afterFind should have received mapper argument')
assert.isDefined(id, 'afterFind should have received id argument')
assert.equal(id, userId, 'afterFind should have received correct id argument')
assert.isObject(opts, 'afterFind should have received opts argument')

@@ -47,35 +53,44 @@ assert.isObject(record, 'afterFind should have received record argument')

assert.debug('find', user[User.idAttribute])
let foundUser = await adapter.find(User, user[User.idAttribute])
assert.debug('found', JSON.stringify(foundUser, null, 2))
assert.debug('find', User.name, userId)
let foundUser = await adapter.find(User, userId)
assert.debug('found', User.name, foundUser)
assert.equal(foundUser.name, 'John', 'name of found user should be "John"')
assert.equal(foundUser[User.idAttribute], userId, 'found user should have correct id')
assert.isTrue(beforeFindCalled, 'beforeFind should have been called')
assert.isTrue(afterFindCalled, 'afterFind should have been called')
// should allow re-assignment
beforeFindCalled = false
afterFindCalled = false
adapter.afterFind = function (mapper, id, opts, record) {
afterFindCalled = true
assert.isObject(mapper, 'afterFind should have received mapper argument')
assert.isDefined(id, 'afterFind should have received id argument')
assert.equal(id, userId, 'afterFind should have received correct id argument')
assert.isObject(opts, 'afterFind should have received opts argument')
assert.isObject(record, 'afterFind should have received record argument')
// Test re-assignment
return Promise.resolve({ name: 'Sally', [User.idAttribute]: user[User.idAttribute] })
return Promise.resolve({ name: 'Sally', [User.idAttribute]: userId })
}
assert.debug('find', user[User.idAttribute])
foundUser = await adapter.find(User, user[User.idAttribute])
assert.debug('found', JSON.stringify(foundUser, null, 2))
assert.equal(foundUser.name, 'Sally', 'name of found user should be "Sally"')
assert.equal(foundUser[User.idAttribute], userId, 'found user should have correct id')
// clear hook
assert.debug('find', User.name, userId)
foundUser = await adapter.find(User, userId)
assert.debug('found', User.name, foundUser)
assert.equal(foundUser.name, 'Sally', 'foundUser.name')
assert.equal(foundUser[User.idAttribute], userId, 'foundUser[User.idAttribute]')
assert.isTrue(beforeFindCalled, 'beforeFind should have been called')
assert.isTrue(afterFindCalled, 'afterFind should have been called')
// clear hooks
delete adapter.beforeFind
delete adapter.afterFind
props = { content: 'test', userId: userId }
assert.debug('create', props)
assert.debug('create', Post.name, props)
const post = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post, null, 2))
assert.debug('created', Post.name, post)
const postId = post[Post.idAttribute]
assert.equal(post.content, 'test')
assert.isDefined(post[Post.idAttribute], 'created post should have an id')
assert.equal(post.userId, userId, 'created post should have user foreign key')
assert.equal(post.content, 'test', 'post.content')
assert.isDefined(post[Post.idAttribute], 'post[Post.idAttribute]')
assert.equal(post.userId, userId, 'post.userId')

@@ -85,12 +100,12 @@ props = [

content: 'test2',
postId: post[Post.idAttribute],
userId: user[User.idAttribute]
postId,
userId
},
{
content: 'test3',
postId: post[Post.idAttribute],
userId: user[User.idAttribute]
postId,
userId
}
]
assert.debug('create', props)
assert.debug('create', Comment.name, props)
const comments = await Promise.all([

@@ -100,3 +115,3 @@ adapter.create(Comment, props[0]),

])
assert.debug('created', JSON.stringify(comments, null, 2))
assert.debug('created', Comment.name, comments)

@@ -107,10 +122,10 @@ comments.sort(function (a, b) {

assert.debug('find', postId)
const findPost = await adapter.find(Post, postId, { with: ['user', 'comment'] })
assert.debug('found', findPost)
findPost.comments.sort(function (a, b) {
assert.debug('find', Post.name, postId)
const foundPost = await adapter.find(Post, postId, { with: ['user', 'comment'] })
assert.debug('found', Post.name, foundPost)
foundPost.comments.sort(function (a, b) {
return a.content > b.content
})
assert.equalObjects(findPost.user, user, 'found post should have attached user')
assert.equalObjects(findPost.comments, comments, 'found post should have attached comments')
assert.equalObjects(foundPost.user, user, 'foundPost.user')
assert.equalObjects(foundPost.comments, comments, 'foundPost.comments')
})

@@ -120,33 +135,33 @@

let props = { name: 'John' }
assert.debug('create', props)
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
assert.debug('created', User.name, user)
const userId = user[User.idAttribute]
assert.equal(user.name, 'John', 'name of created user should be "John"')
assert.isDefined(user[User.idAttribute], 'created user should have an id')
assert.equal(user.name, 'John', 'user.name')
assert.isDefined(user[User.idAttribute], 'user[User.idAttribute]')
assert.debug('find', user[User.idAttribute])
const result = await adapter.find(User, user[User.idAttribute], { raw: true })
assert.debug('found', JSON.stringify(result, null, 2))
assert.isDefined(result.data, 'result.data is defined')
assert.isDefined(result.found, 'result.found is defined')
assert.equal(result.data.name, 'John', 'result.data.name should be "John"')
assert.equal(result.data[User.idAttribute], userId, `result.data.${User.idAttribute} should be ${userId}`)
assert.equal(result.found, 1, 'result.found should be 1')
assert.debug('find', User.name, userId)
const result = await adapter.find(User, userId, { raw: true })
assert.debug('found', User.name, result)
assert.isDefined(result.data, 'result.data')
assert.isDefined(result.found, 'result.found')
assert.equal(result.data.name, 'John', 'result.data.name')
assert.equal(result.data[User.idAttribute], userId, `result.data.${User.idAttribute}`)
assert.equal(result.found, 1, 'result.found')
})
it('should return nothing', async function () {
assert.debug('find', 'non-existent-id')
assert.debug('find', User.name, 'non-existent-id')
const result = await adapter.find(User, 'non-existent-id')
assert.debug('found', JSON.stringify(result, null, 2))
assert.isUndefined(result, 'result should be undefined')
assert.debug('found', User.name, result)
assert.isUndefined(result, 'result')
})
it('should return raw and nothing', async function () {
assert.debug('find', 'non-existent-id')
assert.debug('find', User.name, 'non-existent-id')
const result = await adapter.find(User, 'non-existent-id', { raw: true })
assert.debug('found', JSON.stringify(result, null, 2))
assert.isUndefined(result.data, 'result.data should be undefined')
assert.isDefined(result.found, 'result.found is defined')
assert.equal(result.found, 0, 'result.found should be 0')
assert.debug('found', User.name, result)
assert.isUndefined(result.data, 'result.data')
assert.isDefined(result.found, 'result.found')
assert.equal(result.found, 0, 'result.found')
})

@@ -156,30 +171,30 @@

let props = { name: 'John' }
assert.debug('create', props)
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
assert.debug('created', User.name, user)
props = { email: 'foo@test.com', userId: user[User.idAttribute] }
assert.debug('create', props)
assert.debug('create', Profile.name, props)
const profile = await adapter.create(Profile, props)
assert.debug('created', JSON.stringify(profile, null, 2))
assert.debug('created', Profile.name, profile)
props = { content: 'foo', userId: user[User.idAttribute] }
assert.debug('create', props)
assert.debug('create', Post.name, props)
const post = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post, null, 2))
assert.debug('created', Post.name, post)
props = { content: 'test2', postId: post[Post.idAttribute], userId: post.userId }
assert.debug('create', props)
assert.debug('create', Comment.name, props)
let comment = await adapter.create(Comment, props)
assert.debug('created', JSON.stringify(comment, null, 2))
assert.debug('created', Comment.name, comment)
assert.debug('find', comment[Comment.idAttribute])
assert.debug('find', Comment.name, comment[Comment.idAttribute])
comment = await adapter.find(Comment, comment[Comment.idAttribute], {'with': ['user', 'user.profile', 'post', 'post.user']})
assert.debug('found', JSON.stringify(comment, null, 2))
assert.debug('found', Comment.name, comment)
assert.isDefined(comment)
assert.isDefined(comment.post)
assert.isDefined(comment.post.user)
assert.isDefined(comment.user)
assert.isDefined(comment.user.profile)
assert.isDefined(comment, 'comment')
assert.isDefined(comment.post, 'comment.post')
assert.isDefined(comment.post.user, 'comment.post.user')
assert.isDefined(comment.user, 'comment.user')
assert.isDefined(comment.user.profile, 'comment.user.profile')
})

@@ -189,29 +204,30 @@

let props = { name: 'John' }
assert.debug('create', props)
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
assert.debug('created', User.name, user)
props = { email: 'foo@test.com', userId: user[User.idAttribute] }
assert.debug('create', props)
assert.debug('create', Profile.name, props)
const profile = await adapter.create(Profile, props)
assert.debug('created', JSON.stringify(profile, null, 2))
assert.debug('created', Profile.name, profile)
props = { content: 'foo', userId: user[User.idAttribute] }
assert.debug('create', props)
assert.debug('create', Post.name, props)
let post = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post, null, 2))
let postId = post[Post.idAttribute]
assert.debug('created', Post.name, post)
props = { content: 'test2', postId: post[Post.idAttribute], userId: post.userId }
assert.debug('create', props)
props = { content: 'test2', postId, userId: post.userId }
assert.debug('create', Comment.name, props)
const comment = await adapter.create(Comment, props)
assert.debug('created', JSON.stringify(comment, null, 2))
assert.debug('created', Comment.name, comment)
assert.debug('find', props, comment[Comment.idAttribute])
post = await adapter.find(Post, post[Post.idAttribute], {'with': ['user', 'comment', 'comment.user', 'comment.user.profile']})
assert.debug('found', JSON.stringify(post, null, 2))
assert.debug('find', Post.name, postId)
post = await adapter.find(Post, postId, {'with': ['user', 'comment', 'comment.user', 'comment.user.profile']})
assert.debug('found', Post.name, post)
assert.isDefined(post.comments)
assert.isDefined(post.comments[0].user)
assert.isDefined(post.comments[0].user.profile)
assert.isDefined(post.user)
assert.isDefined(post.comments, 'post.comments')
assert.isDefined(post.comments[0].user, 'post.comments[0].user')
assert.isDefined(post.comments[0].user.profile, 'post.comments[0].user.profile')
assert.isDefined(post.user, 'post.user')
})

@@ -222,63 +238,66 @@

let props = { value: 'big data' }
assert.debug('create', props)
assert.debug('create', Tag.name, props)
const tag = await adapter.create(Tag, props)
assert.debug('created', JSON.stringify(tag, null, 2))
assert.debug('created', Tag.name, tag)
props = { value: 'servers' }
assert.debug('create', props)
assert.debug('create', Tag.name, props)
const tag2 = await adapter.create(Tag, props)
assert.debug('created', JSON.stringify(tag2, null, 2))
assert.debug('created', Tag.name, tag2)
props = { content: 'test', tagIds: [tag[Tag.idAttribute], tag2[Tag.idAttribute]] }
assert.debug('create', props)
assert.debug('create', Post.name, props)
let post = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post, null, 2))
let postId = post[Post.idAttribute]
assert.debug('created', Post.name, post)
assert.debug('find', props, post[Post.idAttribute])
post = await adapter.find(Post, post[Post.idAttribute], { 'with': ['tag'] })
assert.debug('found', JSON.stringify(post, null, 2))
assert.debug('find', Post.name, postId)
post = await adapter.find(Post, postId, { 'with': ['tag'] })
assert.debug('found', Post.name, post)
assert.isDefined(post.tags)
assert.equal(post.content, 'test')
assert.isDefined(post.tags[0][Tag.idAttribute])
assert.isDefined(post.tags[1][Tag.idAttribute])
assert.isDefined(post.tags, 'post.tags')
assert.equal(post.content, 'test', 'post.content')
assert.isDefined(post.tags[0][Tag.idAttribute], 'post.tags[0][Tag.idAttribute]')
assert.isDefined(post.tags[1][Tag.idAttribute], 'post.tags[1][Tag.idAttribute]')
})
it('should load hasMany localKeys (empty array) relations', async function () {
let props = { content: 'test' }
assert.debug('create', props)
assert.debug('create', Post.name, props)
let post = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post, null, 2))
let postId = post[Post.idAttribute]
assert.debug('created', Post.name, post)
assert.debug('find', props, post[Post.idAttribute])
post = await adapter.find(Post, post[Post.idAttribute], { 'with': ['tag'] })
assert.debug('found', JSON.stringify(post, null, 2))
assert.debug('find', Post.name, postId)
post = await adapter.find(Post, postId, { 'with': ['tag'] })
assert.debug('found', Post.name, post)
assert.isDefined(post.tags)
assert.equal(post.content, 'test')
assert.deepEqual(post.tags, [])
assert.isDefined(post.tags, 'post.tags')
assert.equal(post.content, 'test', 'post.content')
assert.deepEqual(post.tags, [], 'post.tags')
})
it('should load hasMany localKeys (object) relations', async function () {
let props = { value: 'big data' }
assert.debug('create', props)
assert.debug('create', Tag.name, props)
const tag = await adapter.create(Tag, props)
assert.debug('created', JSON.stringify(tag, null, 2))
assert.debug('created', Tag.name, tag)
props = { value: 'servers' }
assert.debug('create', props)
assert.debug('create', Tag.name, props)
const tag2 = await adapter.create(Tag, props)
assert.debug('created', JSON.stringify(tag2, null, 2))
assert.debug('created', Tag.name, tag2)
props = { content: 'test', tagIds: { [tag[Tag.idAttribute]]: true, [tag2[Tag.idAttribute]]: true } }
assert.debug('create', props)
assert.debug('create', Post.name, props)
let post = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post, null, 2))
let postId = post[Post.idAttribute]
assert.debug('created', Post.name, post)
assert.debug('find', props, post[Post.idAttribute])
post = await adapter.find(Post, post[Post.idAttribute], { 'with': ['tag'] })
assert.debug('found', JSON.stringify(post, null, 2))
assert.debug('find', Post.name, postId)
post = await adapter.find(Post, postId, { 'with': ['tag'] })
assert.debug('found', Post.name)
assert.isDefined(post.tags)
assert.equal(post.content, 'test')
assert.isDefined(post.tags[0][Tag.idAttribute])
assert.isDefined(post.tags[1][Tag.idAttribute])
assert.isDefined(post.tags, 'post.tags')
assert.equal(post.content, 'test', 'post.content')
assert.isDefined(post.tags[0][Tag.idAttribute], 'post.tags[0][Tag.idAttribute]')
assert.isDefined(post.tags[1][Tag.idAttribute], 'post.tags[1][Tag.idAttribute]')
})

@@ -290,37 +309,39 @@ }

let props = { value: 'big data' }
assert.debug('create', props)
assert.debug('create', Tag.name, props)
let tag = await adapter.create(Tag, props)
assert.debug('created', JSON.stringify(tag, null, 2))
let tagId = tag[Tag.idAttribute]
assert.debug('created', Tag.name, tag)
props = { value: 'servers' }
assert.debug('create', props)
assert.debug('create', Tag.name, props)
let tag2 = await adapter.create(Tag, props)
assert.debug('created', JSON.stringify(tag2, null, 2))
let tag2Id = tag2[Tag.idAttribute]
assert.debug('created', Tag.name, tag2)
props = { content: 'test', tagIds: [tag[Tag.idAttribute]] }
assert.debug('create', props)
props = { content: 'test', tagIds: [tagId] }
assert.debug('create', Post.name, props)
let post = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post, null, 2))
assert.debug('created', Post.name, post)
props = { content: 'test2', tagIds: [tag[Tag.idAttribute], tag2[Tag.idAttribute]] }
assert.debug('create', props)
props = { content: 'test2', tagIds: [tagId, tag2Id] }
assert.debug('create', Post.name, props)
let post2 = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post2, null, 2))
assert.debug('created', Post.name, post2)
assert.debug('find', props, tag[Tag.idAttribute])
tag = await adapter.find(Tag, tag[Tag.idAttribute], { 'with': ['post'] })
assert.debug('found', JSON.stringify(tag, null, 2))
assert.debug('find', Tag.name, tagId)
tag = await adapter.find(Tag, tagId, { 'with': ['post'] })
assert.debug('found', Tag.name, tag)
assert.isDefined(tag.posts)
assert.equal(tag.value, 'big data')
assert.equal(tag.posts.length, 2, 'tag should have two posts')
assert.isDefined(tag.posts, 'tag.posts')
assert.equal(tag.value, 'big data', 'tag.value')
assert.equal(tag.posts.length, 2, 'tag.posts.length')
assert.debug('find', props, tag2[Tag.idAttribute])
tag2 = await adapter.find(Tag, tag2[Tag.idAttribute], { 'with': ['post'] })
assert.debug('found', JSON.stringify(tag2, null, 2))
assert.debug('find', Tag.name, tag2Id)
tag2 = await adapter.find(Tag, tag2Id, { 'with': ['post'] })
assert.debug('found', Tag.name, tag2)
assert.isDefined(tag2.posts)
assert.equal(tag2.value, 'servers')
assert.equal(tag2.posts.length, 1, 'tag2 should have one post')
assert.objectsEqual(tag2.posts, [post2])
assert.isDefined(tag2.posts, 'tag2.posts')
assert.equal(tag2.value, 'servers', 'tag2.value')
assert.equal(tag2.posts.length, 1, 'tag2.posts.length')
assert.objectsEqual(tag2.posts, [post2], 'tag2.posts')
})

@@ -327,0 +348,0 @@ }

@@ -20,19 +20,19 @@ /* global assert:true */

let props = { name: 'John' }
assert.debug('findAll', { age: 30 })
assert.debug('findAll', User.name, { age: 30 })
const users = await adapter.findAll(User, { age: 30 })
assert.debug('found', JSON.stringify(users, null, 2))
assert.equal(users.length, 0)
assert.debug('found', User.name, users)
assert.equal(users.length, 0, 'users.length')
assert.debug('create', props)
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
assert.debug('created', User.name, user)
const userId = user[User.idAttribute]
assert.debug('findAll', { name: 'John' })
assert.debug('findAll', User.name, { name: 'John' })
const users2 = await adapter.findAll(User, { name: 'John' })
assert.debug('found', JSON.stringify(users2, null, 2))
assert.debug('found', User.name, users2)
assert.equal(users2.length, 1)
assert.equal(users2[0][User.idAttribute], userId)
assert.equal(users2[0].name, 'John')
assert.equal(users2.length, 1, 'users2.length')
assert.equal(users2[0][User.idAttribute], userId, 'users2[0][User.idAttribute]')
assert.equal(users2[0].name, 'John', users2[0].name)
})

@@ -49,11 +49,11 @@

})
assert.equal(users.length, 0)
assert.equal(users.length, 0, 'users.length')
var user = await adapter.create(User, {name: 'John'})
var id = user.id
var id = user[User.idAttribute]
var users2 = await adapter.findAll(User, { name: 'John' })
assert.equal(users2.length, 1)
assert.equal(users2[0].id, id)
assert.equal(users2[0].name, 'John')
assert.equal(users2.length, 1, 'users2.length')
assert.equal(users2[0][User.idAttribute], id, 'users2[0][User.idAttribute]')
assert.equal(users2[0].name, 'John', 'users2[0].name')
})

@@ -105,47 +105,47 @@ }

let props = { name: 'John' }
assert.debug('create', props)
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
assert.debug('created', User.name, user)
props = { email: 'foo@test.com', userId: user[User.idAttribute] }
assert.debug('create', props)
assert.debug('create', Profile.name, props)
const profile = await adapter.create(Profile, props)
assert.debug('created', JSON.stringify(profile, null, 2))
assert.debug('created', Profile.name, profile)
props = { content: 'foo', userId: user[User.idAttribute] }
assert.debug('create', props)
assert.debug('create', Post.name, props)
const post = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post, null, 2))
assert.debug('created', Post.name, post)
props = { content: 'test2', postId: post[Post.idAttribute], userId: post.userId }
assert.debug('create', props)
assert.debug('create', Comment.name, props)
let comment = await adapter.create(Comment, props)
assert.debug('created', JSON.stringify(comment, null, 2))
assert.debug('created', Comment.name, comment)
props = { name: 'Sally' }
assert.debug('create', props)
assert.debug('create', User.name, props)
const user2 = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user2, null, 2))
assert.debug('created', User.name, user2)
props = { content: 'bar', userId: user2[User.idAttribute] }
assert.debug('create', props)
assert.debug('create', Post.name, props)
const post2 = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post2, null, 2))
assert.debug('created', Post.name, post2)
props = { content: 'test67', postId: post2[Post.idAttribute], userId: post2.userId }
assert.debug('create', props)
assert.debug('create', Comment.name, props)
let comment2 = await adapter.create(Comment, props)
assert.debug('created', JSON.stringify(comment2, null, 2))
assert.debug('created', Comment.name, comment2)
assert.debug('findAll')
assert.debug('findAll', Comment.name, {})
const comments = await adapter.findAll(Comment, {}, {'with': ['user', 'user.profile', 'post', 'post.user']})
assert.debug('found', JSON.stringify(comments, null, 2))
assert.debug('found', Comment.name, comments)
assert.isDefined(comments[0].post)
assert.isDefined(comments[0].post.user)
assert.isDefined(comments[0].user)
assert.isDefined(comments[0].user.profile || comments[1].user.profile)
assert.isDefined(comments[1].post)
assert.isDefined(comments[1].post.user)
assert.isDefined(comments[1].user)
assert.isDefined(comments[0].post, 'comments[0].post')
assert.isDefined(comments[0].post.user, 'comments[0].post.user')
assert.isDefined(comments[0].user, 'comments[0].user')
assert.isDefined(comments[0].user.profile || comments[1].user.profile, 'comments[0].user.profile || comments[1].user.profile')
assert.isDefined(comments[1].post, 'comments[1].post')
assert.isDefined(comments[1].post.user, 'comments[1].post.user')
assert.isDefined(comments[1].user, 'comments[1].user')
})

@@ -155,47 +155,47 @@

let props = { name: 'John' }
assert.debug('create', props)
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
assert.debug('created', User.name, user)
props = { email: 'foo@test.com', userId: user[User.idAttribute] }
assert.debug('create', props)
assert.debug('create', Profile.name, props)
const profile = await adapter.create(Profile, props)
assert.debug('created', JSON.stringify(profile, null, 2))
assert.debug('created', Profile.name, profile)
props = { content: 'foo', userId: user[User.idAttribute] }
assert.debug('create', props)
assert.debug('create', Post.name, props)
const post = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post, null, 2))
assert.debug('created', Post.name, post)
props = { content: 'test2', postId: post[Post.idAttribute], userId: post.userId }
assert.debug('create', props)
assert.debug('create', Comment.name, props)
let comment = await adapter.create(Comment, props)
assert.debug('created', JSON.stringify(comment, null, 2))
assert.debug('created', Comment.name, comment)
props = { name: 'Sally' }
assert.debug('create', props)
assert.debug('create', User.name, props)
const user2 = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user2, null, 2))
assert.debug('created', User.name, user2)
props = { content: 'bar', userId: user2[User.idAttribute] }
assert.debug('create', props)
assert.debug('create', Post.name, props)
const post2 = await adapter.create(Post, props)
assert.debug('created', JSON.stringify(post2, null, 2))
assert.debug('created', Post.name, post2)
props = { content: 'test67', postId: post2[Post.idAttribute], userId: post2.userId }
assert.debug('create', props)
assert.debug('create', Comment.name, props)
let comment2 = await adapter.create(Comment, props)
assert.debug('created', JSON.stringify(comment2, null, 2))
assert.debug('created', Comment.name, comment2)
assert.debug('find')
assert.debug('find', Post.name, {})
const posts = await adapter.findAll(Post, {}, {'with': ['user', 'comment', 'comment.user', 'comment.user.profile']})
assert.debug('found', JSON.stringify(posts, null, 2))
assert.debug('found', Post.name, posts)
assert.isDefined(posts[0].comments)
assert.isDefined(posts[0].comments[0].user)
assert.isDefined(posts[0].comments[0].user.profile || posts[1].comments[0].user.profile)
assert.isDefined(posts[0].user)
assert.isDefined(posts[1].comments)
assert.isDefined(posts[1].comments[0].user)
assert.isDefined(posts[1].user)
assert.isDefined(posts[0].comments, 'posts[0].comments')
assert.isDefined(posts[0].comments[0].user, 'posts[0].comments[0].user')
assert.isDefined(posts[0].comments[0].user.profile || posts[1].comments[0].user.profile, 'posts[0].comments[0].user.profile || posts[1].comments[0].user.profile')
assert.isDefined(posts[0].user, 'posts[0].user')
assert.isDefined(posts[1].comments, 'posts[1].comments')
assert.isDefined(posts[1].comments[0].user, 'posts[1].comments[0].user')
assert.isDefined(posts[1].user, 'posts[1].user')
})

@@ -202,0 +202,0 @@

@@ -13,3 +13,6 @@ assert.equalObjects = function (a, b, m) {

if (debug) {
console.log(...args)
args.forEach(function (arg, i) {
args[i] = JSON.stringify(arg, null, 2)
})
console.log('DEBUG (TEST):', ...args)
}

@@ -181,2 +184,3 @@ }

await this.$$adapter.destroyAll(this.$$Organization)
await this.$$adapter.destroyAll(this.$$Tag)
})

@@ -183,0 +187,0 @@ },

@@ -12,5 +12,5 @@ /* global assert:true */

assert.debug('create', props)
assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user, null, 2))
assert.debug('created', User.name, user)

@@ -20,5 +20,5 @@ assert.equal(user.name, props.name, `name of user should be "${props.name}"`)

assert.debug('find', user[User.idAttribute])
assert.debug('find', User.name, user[User.idAttribute])
let foundUser = await adapter.find(User, user[User.idAttribute])
assert.debug('found', JSON.stringify(foundUser, null, 2))
assert.debug('found', User.name, foundUser)

@@ -29,5 +29,5 @@ assert.equal(foundUser.name, props.name, `name of user should be "${props.name}"`)

assert.debug('update', user[User.idAttribute], { name: 'Johnny' })
assert.debug('update', User.name, user[User.idAttribute], { name: 'Johnny' })
let updatedUser = await adapter.update(User, user[User.idAttribute], { name: 'Johnny' })
assert.debug('updated', JSON.stringify(updatedUser, null, 2))
assert.debug('updated', User.name, updatedUser)
assert.equal(updatedUser.name, 'Johnny')

@@ -59,5 +59,5 @@ assert.equal(updatedUser[User.idAttribute], user[User.idAttribute])

}
assert.debug('update', user[User.idAttribute], { name: 'foo' })
assert.debug('update', User.name, user[User.idAttribute], { name: 'foo' })
updatedUser = await adapter.update(User, user[User.idAttribute], { name: 'foo' })
assert.debug('updated', JSON.stringify(updatedUser, null, 2))
assert.debug('updated', User.name, updatedUser)
assert.equal(updatedUser.name, 'barbaz')

@@ -68,5 +68,5 @@ assert.equal(updatedUser[User.idAttribute], user[User.idAttribute])

assert.debug('find', user[User.idAttribute])
assert.debug('find', User.name, user[User.idAttribute])
foundUser = await adapter.find(User, user[User.idAttribute])
assert.debug('found', JSON.stringify(foundUser, null, 2))
assert.debug('found', User.name, foundUser)
assert.equal(foundUser.name, 'bar')

@@ -73,0 +73,0 @@ assert.equal(foundUser[User.idAttribute], user[User.idAttribute])

@@ -12,5 +12,5 @@ /* global assert:true */

assert.debug('create', props)
assert.debug('create', User.name, props)
const user1 = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user1, null, 2))
assert.debug('created', User.name, user1)
const userId1 = user1[User.idAttribute]

@@ -20,10 +20,10 @@

assert.debug('create', props)
assert.debug('create', User.name, props)
const user2 = await adapter.create(User, props)
assert.debug('created', JSON.stringify(user2, null, 2))
assert.debug('created', User.name, user2)
const userId2 = user2[User.idAttribute]
assert.debug('findAll', { name: 'John' })
assert.debug('findAll', User.name, { name: 'John' })
const users = await adapter.findAll(User, { name: 'John' })
assert.debug('found', JSON.stringify(users, null, 2))
assert.debug('found', User.name, users)
users.sort(function (a, b) {

@@ -39,5 +39,5 @@ return a.age - b.age

assert.debug('updateAll', { name: 'Johnny' }, { name: 'John' })
assert.debug('updateAll', User.name, { name: 'Johnny' }, { name: 'John' })
const users2 = await adapter.updateAll(User, { name: 'Johnny' }, { name: 'John' })
assert.debug('updated', JSON.stringify(users2, null, 2))
assert.debug('updated', User.name, users2)
users2.sort(function (a, b) {

@@ -53,11 +53,11 @@ return a.age - b.age

assert.debug('findAll', { name: 'John' })
assert.debug('findAll', User.name, { name: 'John' })
const users3 = await adapter.findAll(User, { name: 'John' })
assert.debug('found', JSON.stringify(users3, null, 2))
assert.debug('found', User.name, users3)
assert.equalObjects(users3, [])
assert.equal(users3.length, 0)
assert.debug('findAll', { name: 'Johnny' })
assert.debug('findAll', User.name, { name: 'Johnny' })
const users4 = await adapter.findAll(User, { name: 'Johnny' })
assert.debug('found', JSON.stringify(users4, null, 2))
assert.debug('found', User.name, users4)

@@ -64,0 +64,0 @@ users4.sort(function (a, b) {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc