js-data-adapter-tests
Advanced tools
Comparing version 1.4.3 to 1.5.0
@@ -0,1 +1,5 @@ | ||
##### 1.5.0 - 18 February 2016 | ||
- Some improvements | ||
##### 1.3.0 - 10 November 2015 | ||
@@ -15,2 +19,2 @@ | ||
- Initial release | ||
- Initial release |
{ | ||
"name": "js-data-adapter-tests", | ||
"description": "Tests for js-data adapters.", | ||
"version": "1.4.3", | ||
"homepage": "http://www.js-data.io", | ||
"version": "1.5.0", | ||
"homepage": "https://github.com/js-data/js-data-adapter-tests", | ||
"repository": { | ||
@@ -10,7 +10,3 @@ "type": "git", | ||
}, | ||
"author": { | ||
"name": "Jason Dobry", | ||
"url": "http://www.pseudobry.com", | ||
"email": "jason.dobry@gmail.com" | ||
}, | ||
"author": "Jason Dobry <jason.dobry@gmail.com> (http://www.pseudobry.com)", | ||
"license": "MIT", | ||
@@ -23,12 +19,6 @@ "main": "./dist/js-data-adapter-tests.js", | ||
], | ||
"devDependencies": { | ||
"babel-core": "6.1.2", | ||
"babel-eslint": "4.1.3", | ||
"babel-loader": "6.1.0", | ||
"babel-polyfill": "6.0.16", | ||
"babel-preset-es2015": "6.1.2", | ||
"chai": "3.4.0", | ||
"co-mocha": "^1.1.2", | ||
"standard": "5.3.1", | ||
"webpack": "1.12.4" | ||
"scripts": { | ||
"lint": "standard src/**/*.js", | ||
"bundle": "webpack --config webpack.config.js", | ||
"test": "npm run lint && npm run bundle" | ||
}, | ||
@@ -48,7 +38,14 @@ "standard": { | ||
}, | ||
"scripts": { | ||
"lint": "standard src/**/*.js", | ||
"bundle": "webpack --config webpack.config.js", | ||
"test": "npm run lint && npm run bundle" | ||
"devDependencies": { | ||
"babel-core": "6.5.2", | ||
"babel-eslint": "5.0.0", | ||
"babel-loader": "6.2.3", | ||
"babel-plugin-syntax-async-functions": "6.5.0", | ||
"babel-plugin-transform-regenerator": "6.5.2", | ||
"babel-polyfill": "6.5.0", | ||
"babel-preset-es2015": "6.5.0", | ||
"babel-preset-stage-0": "6.5.0", | ||
"standard": "6.0.5", | ||
"webpack": "1.12.13" | ||
} | ||
} |
@@ -0,0 +0,0 @@ <img src="https://raw.githubusercontent.com/js-data/js-data/master/js-data.png" alt="js-data logo" title="js-data" align="right" width="64" height="64" /> |
module.exports = function (options) { | ||
describe('Adapter#create', function () { | ||
it('should exist', function * () { | ||
it('should exist', function () { | ||
assert.equal(typeof this.$$adapter.create, 'function', 'adapter should have a "create" method') | ||
}) | ||
it('should create a user', function * () { | ||
var adapter = this.$$adapter | ||
var User = this.$$User | ||
var createUser = yield adapter.create(User, {name: 'John'}) | ||
var id = createUser.id | ||
assert.equal(createUser.name, 'John') | ||
assert.isDefined(createUser.id) | ||
it('should create a user', async function () { | ||
const adapter = this.$$adapter | ||
const User = this.$$User | ||
const props = { name: 'John' } | ||
var findUser = yield adapter.find(User, createUser.id) | ||
assert.equal(findUser.name, 'John') | ||
assert.isDefined(findUser.id) | ||
assert.equal(findUser.id, id) | ||
assert.equal(findUser.name, 'John') | ||
assert.debug('create', props) | ||
const user = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user, null, 2)) | ||
var destoryUser = yield adapter.destroy(User, findUser.id) | ||
assert.isFalse(!!destoryUser) | ||
assert.equal(user.name, props.name, `name of user should be "${props.name}"`) | ||
assert.isDefined(user[User.idAttribute], 'new user should have an id') | ||
try { | ||
yield adapter.find(User, id) | ||
throw new Error('Should not have reached here!') | ||
} catch (err) { | ||
assert.equal(err.message, 'Not Found!') | ||
} | ||
assert.debug('find', user[User.idAttribute]) | ||
const foundUser = await adapter.find(User, user[User.idAttribute]) | ||
assert.debug('found', JSON.stringify(foundUser, null, 2)) | ||
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]) | ||
}) | ||
}) | ||
} |
module.exports = function (options) { | ||
describe('Adapter#destroy', function () { | ||
it('should exist', function * () { | ||
it('should exist', function () { | ||
assert.equal(typeof this.$$adapter.destroy, 'function', 'adapter should have a "destroy" method') | ||
}) | ||
it('should destroy a user', function * () { | ||
var adapter = this.$$adapter | ||
var User = this.$$User | ||
var createUser = yield adapter.create(User, {name: 'John'}) | ||
var id = createUser.id | ||
it('should destroy a user', async function () { | ||
const adapter = this.$$adapter | ||
const User = this.$$User | ||
const props = { name: 'John' } | ||
var destroyUser = yield adapter.destroy(User, createUser.id) | ||
assert.isFalse(!!destroyUser) | ||
assert.debug('create', props) | ||
const user = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user, null, 2)) | ||
assert.debug('destroy', user[User.idAttribute]) | ||
const destroyedUser = await adapter.destroy(User, user[User.idAttribute]) | ||
assert.debug('destroyed', JSON.stringify(destroyedUser, null, 2)) | ||
assert.isFalse(!!destroyedUser) | ||
try { | ||
yield adapter.find(User, id) | ||
await adapter.find(User, user[User.idAttribute]) | ||
throw new Error('Should not have reached here!') | ||
@@ -18,0 +23,0 @@ } catch (err) { |
module.exports = function (options) { | ||
describe('Adapter#destroyAll', function () { | ||
it('should exist', function * () { | ||
it('should exist', function () { | ||
assert.equal(typeof this.$$adapter.destroyAll, 'function', 'adapter should have a "destroyAll" method') | ||
}) | ||
it('should destroy all users', function * () { | ||
var adapter = this.$$adapter | ||
var User = this.$$User | ||
var createUser = yield adapter.create(User, {name: 'John'}) | ||
var id = createUser.id | ||
it('should destroy all users', async function () { | ||
const adapter = this.$$adapter | ||
const User = this.$$User | ||
const props = { name: 'John' } | ||
var findUsers = yield adapter.findAll(User, { name: 'John' }) | ||
assert.equal(findUsers.length, 1) | ||
assert.equal(findUsers[0].id, id) | ||
assert.equal(findUsers[0].name, 'John') | ||
assert.debug('create', props) | ||
const user = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user, null, 2)) | ||
yield adapter.destroyAll(User, { name: 'John' }) | ||
var findUsers2 = yield adapter.findAll(User, { name: 'John' }) | ||
assert.equal(findUsers2.length, 0) | ||
assert.debug('findAll', 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('destroyAll', props) | ||
const destroyedUsers = await adapter.destroyAll(User, props) | ||
assert.debug('destroyed', JSON.stringify(destroyedUsers, null, 2)) | ||
assert.debug('findAll', props) | ||
foundUsers = await adapter.findAll(User, props) | ||
assert.debug('found', JSON.stringify(foundUsers, null, 2)) | ||
assert.equal(foundUsers.length, 0) | ||
}) | ||
}) | ||
} |
@@ -13,36 +13,50 @@ module.exports = function (options) { | ||
it('should exist', function * () { | ||
it('should exist', function () { | ||
assert.equal(typeof adapter.find, 'function', 'adapter should have a "find" method') | ||
}) | ||
it('should find a user', function * () { | ||
var user = yield adapter.create(User, {name: 'John'}) | ||
var userId = user.id | ||
assert.equal(user.name, 'John') | ||
assert.isDefined(user.id) | ||
it('should find a user', async function () { | ||
let props = { name: 'John' } | ||
assert.debug('create', props) | ||
const user = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user, null, 2)) | ||
const userId = user[User.idAttribute] | ||
assert.equal(user.name, 'John', 'name of created user should be "John"') | ||
assert.isDefined(user[User.idAttribute]) | ||
var user2 = yield adapter.find(User, user.id) | ||
assert.equal(user2.name, 'John') | ||
assert.isDefined(user2.id) | ||
assert.equal(user2.id, userId) | ||
assert.equal(user2.name, 'John') | ||
assert.debug('find', user[User.idAttribute]) | ||
const foundUser = await adapter.find(User, user[User.idAttribute]) | ||
assert.debug('found', JSON.stringify(foundUser, null, 2)) | ||
assert.equal(foundUser.name, 'John') | ||
assert.isDefined(foundUser[User.idAttribute]) | ||
assert.equal(foundUser[User.idAttribute], userId) | ||
assert.equal(foundUser.name, 'John') | ||
var post = yield adapter.create(Post, { content: 'test', userId: userId }) | ||
var postId = post.id | ||
props = { content: 'test', userId: userId } | ||
assert.debug('create', props) | ||
const post = await adapter.create(Post, props) | ||
assert.debug('created', JSON.stringify(post, null, 2)) | ||
const postId = post[Post.idAttribute] | ||
assert.equal(post.content, 'test') | ||
assert.isDefined(post.id) | ||
assert.isDefined(post.userId) | ||
assert.isDefined(post[Post.idAttribute]) | ||
assert.equal(post.userId, userId) | ||
var comments = yield [ | ||
adapter.create(Comment, { | ||
props = [ | ||
{ | ||
content: 'test2', | ||
postId: post.id, | ||
userId: user.id | ||
}), | ||
adapter.create(Comment, { | ||
postId: post[Post.idAttribute], | ||
userId: user[User.idAttribute] | ||
}, | ||
{ | ||
content: 'test3', | ||
postId: post.id, | ||
userId: user.id | ||
}) | ||
postId: post[Post.idAttribute], | ||
userId: user[User.idAttribute] | ||
} | ||
] | ||
assert.debug('create', props) | ||
const comments = await Promise.all([ | ||
adapter.create(Comment, props[0]), | ||
adapter.create(Comment, props[1]) | ||
]) | ||
assert.debug('created', JSON.stringify(comments, null, 2)) | ||
@@ -53,3 +67,3 @@ comments.sort(function (a, b) { | ||
var findPost = yield adapter.find(Post, postId, {with: ['user', 'comment']}) | ||
const findPost = await adapter.find(Post, postId, {with: ['user', 'comment']}) | ||
findPost.comments.sort(function (a, b) { | ||
@@ -60,23 +74,28 @@ return a.content > b.content | ||
assert.equalObjects(findPost.comments, comments) | ||
}) | ||
yield adapter.destroyAll(Comment) | ||
yield adapter.destroy(Post, postId) | ||
var destroyUser = yield adapter.destroy(User, userId) | ||
assert.isFalse(!!destroyUser) | ||
it('should load belongsTo relations', async function () { | ||
let props = { name: 'John' } | ||
assert.debug('create', props) | ||
const user = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user, null, 2)) | ||
try { | ||
yield adapter.find(User, userId) | ||
throw new Error('Should not have reached here!') | ||
} catch (err) { | ||
assert.equal(err.message, 'Not Found!') | ||
} | ||
}) | ||
props = { email: 'foo@test.com', userId: user[User.idAttribute] } | ||
assert.debug('create', props) | ||
const profile = await adapter.create(Profile, props) | ||
assert.debug('created', JSON.stringify(profile, null, 2)) | ||
it('should load belongsTo relations', function * () { | ||
var profile = yield adapter.create(Profile, { email: 'foo@test.com' }) | ||
var user = yield adapter.create(User, {name: 'John', profileId: profile.id}) | ||
var post = yield adapter.create(Post, {content: 'foo', userId: user.id}) | ||
var comment = yield adapter.create(Comment, { content: 'test2', postId: post.id, userId: post.userId }) | ||
props = { content: 'foo', userId: user[User.idAttribute] } | ||
assert.debug('create', props) | ||
const post = await adapter.create(Post, props) | ||
assert.debug('created', JSON.stringify(post, null, 2)) | ||
comment = yield adapter.find(Comment, comment.id, {'with': ['user', 'user.profile', 'post', 'post.user']}) | ||
props = { content: 'test2', postId: post[Post.idAttribute], userId: post.userId } | ||
assert.debug('create', props) | ||
let comment = await adapter.create(Comment, props) | ||
assert.debug('created', JSON.stringify(comment, null, 2)) | ||
assert.debug('find', 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.isDefined(comment) | ||
@@ -89,15 +108,33 @@ assert.isDefined(comment.post) | ||
it('should load hasMany and belongsTo relations', function * () { | ||
var profile = yield adapter.create(Profile, { email: 'foo@test.com' }) | ||
var user = yield adapter.create(User, {name: 'John', profileId: profile.id}) | ||
var post = yield adapter.create(Post, {content: 'foo', userId: user.id}) | ||
yield adapter.create(Comment, { content: 'test2', postId: post.id, userId: post.userId }) | ||
it('should load hasMany and belongsTo relations', async function () { | ||
let props = { name: 'John' } | ||
assert.debug('create', props) | ||
const user = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user, null, 2)) | ||
var foundPost = yield adapter.find(Post, post.id, {'with': ['user', 'comment', 'comment.user', 'comment.user.profile']}) | ||
assert.isDefined(foundPost.comments) | ||
assert.isDefined(foundPost.comments[0].user) | ||
assert.isDefined(foundPost.comments[0].user.profile) | ||
assert.isDefined(foundPost.user) | ||
props = { email: 'foo@test.com', userId: user[User.idAttribute] } | ||
assert.debug('create', props) | ||
const profile = await adapter.create(Profile, props) | ||
assert.debug('created', JSON.stringify(profile, null, 2)) | ||
props = { content: 'foo', userId: user[User.idAttribute] } | ||
assert.debug('create', props) | ||
let post = await adapter.create(Post, props) | ||
assert.debug('created', JSON.stringify(post, null, 2)) | ||
props = { content: 'test2', postId: post[Post.idAttribute], userId: post.userId } | ||
assert.debug('create', props) | ||
const comment = await adapter.create(Comment, props) | ||
assert.debug('created', JSON.stringify(comment, null, 2)) | ||
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.isDefined(post.comments) | ||
assert.isDefined(post.comments[0].user) | ||
assert.isDefined(post.comments[0].user.profile) | ||
assert.isDefined(post.user) | ||
}) | ||
}) | ||
} |
@@ -13,74 +13,82 @@ module.exports = function (options) { | ||
it('should exist', function * () { | ||
it('should exist', function () { | ||
assert.equal(typeof adapter.findAll, 'function', 'adapter should have a "findAll" method') | ||
}) | ||
it('should filter users', function * () { | ||
var users = yield adapter.findAll(User, { age: 30 }) | ||
it('should filter users', async function () { | ||
let props = { name: 'John' } | ||
assert.debug('findAll', { age: 30 }) | ||
const users = await adapter.findAll(User, { age: 30 }) | ||
assert.debug('found', JSON.stringify(users, null, 2)) | ||
assert.equal(users.length, 0) | ||
var user = yield adapter.create(User, {name: 'John'}) | ||
var id = user.id | ||
assert.debug('create', props) | ||
const user = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user, null, 2)) | ||
const userId = user[User.idAttribute] | ||
var users2 = yield adapter.findAll(User, { name: 'John' }) | ||
assert.debug('findAll', { name: 'John' }) | ||
const users2 = await adapter.findAll(User, { name: 'John' }) | ||
assert.debug('found', JSON.stringify(users2, null, 2)) | ||
assert.equal(users2.length, 1) | ||
assert.equal(users2[0].id, id) | ||
assert.equal(users2[0][User.idAttribute], userId) | ||
assert.equal(users2[0].name, 'John') | ||
var destroyedUser = yield adapter.destroy(User, id) | ||
assert.isFalse(!!destroyedUser) | ||
}) | ||
it('should filter users using the "in" operator', function * () { | ||
var users = yield adapter.findAll(User, { | ||
where: { | ||
age: { | ||
'in': [30] | ||
if (options.features === 'all' || options.features.indexOf('inOp') !== -1) { | ||
it('should filter users using the "in" operator', async function () { | ||
var users = await adapter.findAll(User, { | ||
where: { | ||
age: { | ||
'in': [30] | ||
} | ||
} | ||
} | ||
}) | ||
assert.equal(users.length, 0) | ||
}) | ||
assert.equal(users.length, 0) | ||
var user = yield adapter.create(User, {name: 'John'}) | ||
var id = user.id | ||
var user = await adapter.create(User, {name: 'John'}) | ||
var id = user.id | ||
var users2 = yield adapter.findAll(User, { name: 'John' }) | ||
assert.equal(users2.length, 1) | ||
assert.equal(users2[0].id, id) | ||
assert.equal(users2[0].name, 'John') | ||
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') | ||
var destroyedUser = yield adapter.destroy(User, id) | ||
assert.isFalse(!!destroyedUser) | ||
}) | ||
var destroyedUser = await adapter.destroy(User, id) | ||
assert.isFalse(!!destroyedUser) | ||
}) | ||
} | ||
it('should filter users using the "like" operator', function * () { | ||
var users = yield adapter.findAll(User, { | ||
where: { | ||
name: { | ||
'like': '%J%' | ||
if (options.features === 'all' || options.features.indexOf('likeOp') !== -1) { | ||
it('should filter users using the "like" operator', async function () { | ||
var users = await adapter.findAll(User, { | ||
where: { | ||
name: { | ||
'like': '%J%' | ||
} | ||
} | ||
} | ||
}) | ||
assert.equal(users.length, 0) | ||
}) | ||
assert.equal(users.length, 0) | ||
var user = yield adapter.create(User, {name: 'John'}) | ||
var id = user.id | ||
var user = await adapter.create(User, {name: 'John'}) | ||
var id = user.id | ||
var users2 = yield adapter.findAll(User, { | ||
where: { | ||
name: { | ||
'like': '%J%' | ||
var users2 = await adapter.findAll(User, { | ||
where: { | ||
name: { | ||
'like': '%J%' | ||
} | ||
} | ||
} | ||
}) | ||
assert.equal(users2.length, 1) | ||
assert.equal(users2[0].id, id) | ||
assert.equal(users2[0].name, 'John') | ||
var destroyedUser = await adapter.destroy(User, id) | ||
assert.isFalse(!!destroyedUser) | ||
}) | ||
assert.equal(users2.length, 1) | ||
assert.equal(users2[0].id, id) | ||
assert.equal(users2[0].name, 'John') | ||
} | ||
var destroyedUser = yield adapter.destroy(User, id) | ||
assert.isFalse(!!destroyedUser) | ||
}) | ||
if (options.features === 'all' || options.features.indexOf('filterOpNotFound') !== -1) { | ||
it('should throw "Operator not found" error', function * () { | ||
it('should throw "Operator not found" error', async function () { | ||
assert.throw(function () { | ||
@@ -98,13 +106,41 @@ return adapter.findAll(User, { | ||
it('should load belongsTo relations', function * () { | ||
var profile1 = yield adapter.create(Profile, { email: 'foo@test.com' }) | ||
var user1 = yield adapter.create(User, {name: 'John', profileId: profile1.id}) | ||
var post1 = yield adapter.create(Post, {content: 'foo', userId: user1.id}) | ||
yield adapter.create(Comment, { content: 'test2', postId: post1.id, userId: post1.userId }) | ||
it('should load belongsTo relations', async function () { | ||
let props = { name: 'John' } | ||
assert.debug('create', props) | ||
const user = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user, null, 2)) | ||
var user2 = yield adapter.create(User, {name: 'Sally'}) | ||
var post2 = yield adapter.create(Post, {content: 'bar', userId: user2.id}) | ||
yield adapter.create(Comment, { content: 'test3', postId: post2.id, userId: post2.userId }) | ||
props = { email: 'foo@test.com', userId: user[User.idAttribute] } | ||
assert.debug('create', props) | ||
const profile = await adapter.create(Profile, props) | ||
assert.debug('created', JSON.stringify(profile, null, 2)) | ||
var comments = yield adapter.findAll(Comment, {}, {'with': ['user', 'user.profile', 'post', 'post.user']}) | ||
props = { content: 'foo', userId: user[User.idAttribute] } | ||
assert.debug('create', props) | ||
const post = await adapter.create(Post, props) | ||
assert.debug('created', JSON.stringify(post, null, 2)) | ||
props = { content: 'test2', postId: post[Post.idAttribute], userId: post.userId } | ||
assert.debug('create', props) | ||
let comment = await adapter.create(Comment, props) | ||
assert.debug('created', JSON.stringify(comment, null, 2)) | ||
props = { name: 'Sally' } | ||
assert.debug('create', props) | ||
const user2 = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user2, null, 2)) | ||
props = { content: 'bar', userId: user2[User.idAttribute] } | ||
assert.debug('create', props) | ||
const post2 = await adapter.create(Post, props) | ||
assert.debug('created', JSON.stringify(post2, null, 2)) | ||
props = { content: 'test67', postId: post2[Post.idAttribute], userId: post2.userId } | ||
assert.debug('create', props) | ||
let comment2 = await adapter.create(Comment, props) | ||
assert.debug('created', JSON.stringify(comment2, null, 2)) | ||
assert.debug('findAll') | ||
const comments = await adapter.findAll(Comment, {}, {'with': ['user', 'user.profile', 'post', 'post.user']}) | ||
assert.debug('found', JSON.stringify(comments, null, 2)) | ||
assert.isDefined(comments[0].post) | ||
@@ -119,13 +155,41 @@ assert.isDefined(comments[0].post.user) | ||
it('should load hasMany and belongsTo relations', function * () { | ||
var profile = yield adapter.create(Profile, { email: 'foo@test.com' }) | ||
var user1 = yield adapter.create(User, {name: 'John', profileId: profile.id}) | ||
var post1 = yield adapter.create(Post, {content: 'foo', userId: user1.id}) | ||
yield adapter.create(Comment, { content: 'test2', postId: post1.id, userId: post1.userId }) | ||
it('should load hasMany and belongsTo relations', async function () { | ||
let props = { name: 'John' } | ||
assert.debug('create', props) | ||
const user = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user, null, 2)) | ||
var user2 = yield adapter.create(User, {name: 'Sally'}) | ||
var post2 = yield adapter.create(Post, {content: 'bar', userId: user2.id}) | ||
yield adapter.create(Comment, { content: 'test3', postId: post2.id, userId: post2.userId }) | ||
props = { email: 'foo@test.com', userId: user[User.idAttribute] } | ||
assert.debug('create', props) | ||
const profile = await adapter.create(Profile, props) | ||
assert.debug('created', JSON.stringify(profile, null, 2)) | ||
var posts = yield adapter.findAll(Post, {}, {'with': ['user', 'comment', 'comment.user', 'comment.user.profile']}) | ||
props = { content: 'foo', userId: user[User.idAttribute] } | ||
assert.debug('create', props) | ||
const post = await adapter.create(Post, props) | ||
assert.debug('created', JSON.stringify(post, null, 2)) | ||
props = { content: 'test2', postId: post[Post.idAttribute], userId: post.userId } | ||
assert.debug('create', props) | ||
let comment = await adapter.create(Comment, props) | ||
assert.debug('created', JSON.stringify(comment, null, 2)) | ||
props = { name: 'Sally' } | ||
assert.debug('create', props) | ||
const user2 = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user2, null, 2)) | ||
props = { content: 'bar', userId: user2[User.idAttribute] } | ||
assert.debug('create', props) | ||
const post2 = await adapter.create(Post, props) | ||
assert.debug('created', JSON.stringify(post2, null, 2)) | ||
props = { content: 'test67', postId: post2[Post.idAttribute], userId: post2.userId } | ||
assert.debug('create', props) | ||
let comment2 = await adapter.create(Comment, props) | ||
assert.debug('created', JSON.stringify(comment2, null, 2)) | ||
assert.debug('find') | ||
const posts = await adapter.findAll(Post, {}, {'with': ['user', 'comment', 'comment.user', 'comment.user.profile']}) | ||
assert.debug('found', JSON.stringify(posts, null, 2)) | ||
assert.isDefined(posts[0].comments) | ||
@@ -141,13 +205,13 @@ assert.isDefined(posts[0].comments[0].user) | ||
if (options.features === 'all' || options.features.indexOf('filterOnRelations') !== -1) { | ||
it('should filter using belongsTo relation', function * () { | ||
var profile1 = yield adapter.create(Profile, { email: 'foo@test.com' }) | ||
var user1 = yield adapter.create(User, {name: 'John', profileId: profile1.id}) | ||
var post1 = yield adapter.create(Post, {content: 'foo', userId: user1.id}) | ||
yield adapter.create(Comment, {content: 'test1', postId: post1.id, userId: post1.userId}) | ||
it('should filter using belongsTo relation', async function () { | ||
var profile1 = await adapter.create(Profile, { email: 'foo@test.com' }) | ||
var user1 = await adapter.create(User, {name: 'John', profileId: profile1.id}) | ||
var post1 = await adapter.create(Post, {content: 'foo', userId: user1.id}) | ||
await adapter.create(Comment, {content: 'test1', postId: post1.id, userId: post1.userId}) | ||
var user2 = yield adapter.create(User, {name: 'Sally'}) | ||
var post2 = yield adapter.create(Post, {content: 'bar', userId: user2.id}) | ||
yield adapter.create(Comment, {content: 'test2', postId: post2.id, userId: post2.userId}) | ||
var user2 = await adapter.create(User, {name: 'Sally'}) | ||
var post2 = await adapter.create(Post, {content: 'bar', userId: user2.id}) | ||
await adapter.create(Comment, {content: 'test2', postId: post2.id, userId: post2.userId}) | ||
var users = yield adapter.findAll(User, {'profile.email': 'foo@test.com'}) | ||
var users = await adapter.findAll(User, {'profile.email': 'foo@test.com'}) | ||
assert.equal(users.length, 1) | ||
@@ -158,14 +222,14 @@ assert.equal(users[0].profileId, profile1.id) | ||
it('should filter through multiple hasOne/belongsTo relations', function * () { | ||
var profile1 = yield adapter.create(Profile, { email: 'foo@test.com' }) | ||
var user1 = yield adapter.create(User, {name: 'John', profileId: profile1.id}) | ||
var post1 = yield adapter.create(Post, {content: 'foo', userId: user1.id}) | ||
yield adapter.create(Comment, {content: 'test1', postId: post1.id, userId: post1.userId}) | ||
it('should filter through multiple hasOne/belongsTo relations', async function () { | ||
var profile1 = await adapter.create(Profile, { email: 'foo@test.com' }) | ||
var user1 = await adapter.create(User, {name: 'John', profileId: profile1.id}) | ||
var post1 = await adapter.create(Post, {content: 'foo', userId: user1.id}) | ||
await adapter.create(Comment, {content: 'test1', postId: post1.id, userId: post1.userId}) | ||
var profile2 = yield adapter.create(Profile, { email: 'bar@test.com' }) | ||
var user2 = yield adapter.create(User, {name: 'Sally', profileId: profile2.id}) | ||
var post2 = yield adapter.create(Post, {content: 'bar', userId: user2.id}) | ||
yield adapter.create(Comment, {content: 'test2', postId: post2.id, userId: post2.userId}) | ||
var profile2 = await adapter.create(Profile, { email: 'bar@test.com' }) | ||
var user2 = await adapter.create(User, {name: 'Sally', profileId: profile2.id}) | ||
var post2 = await adapter.create(Post, {content: 'bar', userId: user2.id}) | ||
await adapter.create(Comment, {content: 'test2', postId: post2.id, userId: post2.userId}) | ||
var comments = yield adapter.findAll(Comment, { 'user.profile.email': 'foo@test.com' }) | ||
var comments = await adapter.findAll(Comment, { 'user.profile.email': 'foo@test.com' }) | ||
assert.equal(comments.length, 1) | ||
@@ -176,14 +240,14 @@ assert.equal(comments[0].userId, user1.id) | ||
it('should filter using multiple hasOne/belongsTo relations', function * () { | ||
var profile1 = yield adapter.create(Profile, { email: 'foo@test.com' }) | ||
var user1 = yield adapter.create(User, {name: 'John', profileId: profile1.id}) | ||
var post1 = yield adapter.create(Post, {content: 'foo', userId: user1.id}) | ||
yield adapter.create(Comment, {content: 'test1', postId: post1.id, userId: post1.userId}) | ||
it('should filter using multiple hasOne/belongsTo relations', async function () { | ||
var profile1 = await adapter.create(Profile, { email: 'foo@test.com' }) | ||
var user1 = await adapter.create(User, {name: 'John', profileId: profile1.id}) | ||
var post1 = await adapter.create(Post, {content: 'foo', userId: user1.id}) | ||
await adapter.create(Comment, {content: 'test1', postId: post1.id, userId: post1.userId}) | ||
var profile2 = yield adapter.create(Profile, { email: 'bar@test.com' }) | ||
var user2 = yield adapter.create(User, {name: 'Sally', profileId: profile2.id}) | ||
var post2 = yield adapter.create(Post, {content: 'bar', userId: user2.id}) | ||
yield adapter.create(Comment, {content: 'test2', postId: post2.id, userId: post2.userId}) | ||
var profile2 = await adapter.create(Profile, { email: 'bar@test.com' }) | ||
var user2 = await adapter.create(User, {name: 'Sally', profileId: profile2.id}) | ||
var post2 = await adapter.create(Post, {content: 'bar', userId: user2.id}) | ||
await adapter.create(Comment, {content: 'test2', postId: post2.id, userId: post2.userId}) | ||
var comments = yield adapter.findAll(Comment, { 'user.name': 'John', 'user.profile.email': 'foo@test.com' }) | ||
var comments = await adapter.findAll(Comment, { 'user.name': 'John', 'user.profile.email': 'foo@test.com' }) | ||
assert.equal(comments.length, 1) | ||
@@ -195,6 +259,6 @@ assert.equal(comments[0].userId, user1.id) | ||
it('should allow passing limit and offset as strings', function * () { | ||
yield adapter.findAll(User, {limit: '10', offset: '20'}) | ||
it('should allow passing limit and offset as strings', async function () { | ||
await adapter.findAll(User, { limit: '10', offset: '20' }) | ||
}) | ||
}) | ||
} |
@@ -1,13 +0,15 @@ | ||
require('babel-polyfill') | ||
assert.equalObjects = function (a, b, m) { | ||
assert.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)), m || (JSON.stringify(a) + ' should be equal to ' + JSON.stringify(b))) | ||
} | ||
try { | ||
require('co-mocha')(Mocha) | ||
} catch (err) { | ||
assert.objectsEqual = function (a, b, m) { | ||
assert.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)), m || (JSON.stringify(a) + ' should be equal to ' + JSON.stringify(b))) | ||
} | ||
var assert = require('chai').assert | ||
let debug = false | ||
assert.equalObjects = function (a, b, m) { | ||
assert.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)), m || (JSON.stringify(a) + ' should be equal to ' + JSON.stringify(b))) | ||
assert.debug = function (...args) { | ||
if (debug) { | ||
console.log(...args) | ||
} | ||
} | ||
@@ -20,2 +22,3 @@ | ||
options = options || {} | ||
debug = !!options.debug | ||
options.methods = options.methods || 'all' | ||
@@ -47,7 +50,7 @@ options.features = options.features || 'all' | ||
localField: 'profile', | ||
localKey: 'profileId' | ||
foreignKey: 'userId' | ||
}, | ||
address: { | ||
localField: 'address', | ||
localKey: 'addressId' | ||
foreignKey: 'userId' | ||
} | ||
@@ -58,6 +61,22 @@ } | ||
this.$$Profile = this.$$store.defineResource(options.profileConfig || { | ||
name: 'profile' | ||
name: 'profile', | ||
relations: { | ||
belongsTo: { | ||
user: { | ||
localField: 'user', | ||
localkey: 'userId' | ||
} | ||
} | ||
} | ||
}) | ||
this.$$Address = this.$$store.defineResource(options.addressConfig || { | ||
name: 'address' | ||
name: 'address', | ||
relations: { | ||
belongsTo: { | ||
user: { | ||
localField: 'user', | ||
localkey: 'userId' | ||
} | ||
} | ||
} | ||
}) | ||
@@ -122,8 +141,8 @@ this.$$Post = this.$$store.defineResource(options.postConfig || { | ||
afterEach(function * () { | ||
yield this.$$adapter.destroyAll(this.$$Comment) | ||
yield this.$$adapter.destroyAll(this.$$Post) | ||
yield this.$$adapter.destroyAll(this.$$User) | ||
yield this.$$adapter.destroyAll(this.$$Profile) | ||
yield this.$$adapter.destroyAll(this.$$Address) | ||
afterEach(async function () { | ||
await this.$$adapter.destroyAll(this.$$Comment) | ||
await this.$$adapter.destroyAll(this.$$Post) | ||
await this.$$adapter.destroyAll(this.$$User) | ||
await this.$$adapter.destroyAll(this.$$Profile) | ||
await this.$$adapter.destroyAll(this.$$Address) | ||
}) | ||
@@ -130,0 +149,0 @@ }, |
module.exports = function (options) { | ||
describe('Adapter#update', function () { | ||
it('should exist', function * () { | ||
it('should exist', function () { | ||
assert.equal(typeof this.$$adapter.update, 'function', 'adapter should have a "update" method') | ||
}) | ||
it('should update a user', function * () { | ||
var adapter = this.$$adapter | ||
var User = this.$$User | ||
var user = yield adapter.create(User, {name: 'John'}) | ||
var id = user.id | ||
assert.equal(user.name, 'John') | ||
assert.isDefined(user.id) | ||
it('should update a user', async function () { | ||
const adapter = this.$$adapter | ||
const User = this.$$User | ||
const props = { name: 'John' } | ||
var foundUser = yield adapter.find(User, user.id) | ||
assert.equal(foundUser.name, 'John') | ||
assert.isDefined(foundUser.id) | ||
assert.equal(foundUser.id, id) | ||
assert.equal(foundUser.name, 'John') | ||
assert.debug('create', props) | ||
const user = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user, null, 2)) | ||
var updatedUser = yield adapter.update(User, foundUser.id, {name: 'Johnny'}) | ||
assert.equal(updatedUser.name, 'Johnny') | ||
assert.isDefined(updatedUser.id) | ||
assert.equal(updatedUser.id, id) | ||
assert.equal(updatedUser.name, 'Johnny') | ||
assert.equal(user.name, props.name, `name of user should be "${props.name}"`) | ||
assert.isDefined(user[User.idAttribute], 'new user should have an id') | ||
var foundUser2 = yield adapter.find(User, updatedUser.id) | ||
assert.equal(foundUser2.name, 'Johnny') | ||
assert.isDefined(foundUser2.id) | ||
assert.equal(foundUser2.id, id) | ||
assert.equal(foundUser2.name, 'Johnny') | ||
assert.debug('find', user[User.idAttribute]) | ||
let foundUser = await adapter.find(User, user[User.idAttribute]) | ||
assert.debug('found', JSON.stringify(foundUser, null, 2)) | ||
var destroyUser = yield adapter.destroy(User, foundUser2.id) | ||
assert.isFalse(!!destroyUser) | ||
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]) | ||
try { | ||
yield adapter.find(User, id) | ||
throw new Error('Should not have reached here!') | ||
} catch (err) { | ||
assert.equal(err.message, 'Not Found!') | ||
} | ||
assert.debug('update', user[User.idAttribute], { name: 'Johnny' }) | ||
const updatedUser = await adapter.update(User, user[User.idAttribute], { name: 'Johnny' }) | ||
assert.debug('found', JSON.stringify(updatedUser, null, 2)) | ||
assert.equal(updatedUser.name, 'Johnny') | ||
assert.equal(updatedUser[User.idAttribute], user[User.idAttribute]) | ||
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, 'Johnny') | ||
assert.equal(foundUser[User.idAttribute], user[User.idAttribute]) | ||
}) | ||
}) | ||
} |
module.exports = function (options) { | ||
describe('Adapter#updateAll', function () { | ||
it('should exist', function * () { | ||
it('should exist', function () { | ||
assert.equal(typeof this.$$adapter.updateAll, 'function', 'adapter should have a "updateAll" method') | ||
}) | ||
it('should update multiple users', function * () { | ||
var adapter = this.$$adapter | ||
var User = this.$$User | ||
var user1 = yield adapter.create(User, {name: 'John', age: 20}) | ||
var userId1 = user1.id | ||
it('should update multiple users', async function () { | ||
const adapter = this.$$adapter | ||
const User = this.$$User | ||
let props = { name: 'John', age: 20 } | ||
var user2 = yield adapter.create(User, {name: 'John', age: 30}) | ||
var userId2 = user2.id | ||
assert.debug('create', props) | ||
const user1 = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user1, null, 2)) | ||
const userId1 = user1[User.idAttribute] | ||
var users = yield adapter.findAll(User, { name: 'John' }) | ||
props = { name: 'John', age: 30 } | ||
assert.debug('create', props) | ||
const user2 = await adapter.create(User, props) | ||
assert.debug('created', JSON.stringify(user2, null, 2)) | ||
const userId2 = user2[User.idAttribute] | ||
assert.debug('findAll', { name: 'John' }) | ||
const users = await adapter.findAll(User, { name: 'John' }) | ||
assert.debug('found', JSON.stringify(users, null, 2)) | ||
users.sort(function (a, b) { | ||
@@ -21,8 +31,10 @@ return a.age - b.age | ||
assert.equal(users[0].name, 'John') | ||
assert.equal(users.filter(function (x) { return x.id === userId1 }).length, 1) | ||
assert.equal(users.filter(function (x) { return x.id === userId2 }).length, 1) | ||
assert.equal(users.filter(function (x) { return x[User.idAttribute] === userId1 }).length, 1) | ||
assert.equal(users.filter(function (x) { return x[User.idAttribute] === userId2 }).length, 1) | ||
assert.equal(users.filter(function (x) { return x.age === 20 }).length, 1) | ||
assert.equal(users.filter(function (x) { return x.age === 30 }).length, 1) | ||
var users2 = yield adapter.updateAll(User, { name: 'Johnny' }, { name: 'John' }) | ||
assert.debug('updateAll', { name: 'Johnny' }, { name: 'John' }) | ||
const users2 = await adapter.updateAll(User, { name: 'Johnny' }, { name: 'John' }) | ||
assert.debug('updated', JSON.stringify(users2, null, 2)) | ||
users2.sort(function (a, b) { | ||
@@ -33,12 +45,16 @@ return a.age - b.age | ||
assert.equal(users2[0].name, 'Johnny') | ||
assert.equal(users2.filter(function (x) { return x.id === userId1 }).length, 1) | ||
assert.equal(users2.filter(function (x) { return x.id === userId2 }).length, 1) | ||
assert.equal(users2.filter(function (x) { return x[User.idAttribute] === userId1 }).length, 1) | ||
assert.equal(users2.filter(function (x) { return x[User.idAttribute] === userId2 }).length, 1) | ||
assert.equal(users2.filter(function (x) { return x.age === 20 }).length, 1) | ||
assert.equal(users2.filter(function (x) { return x.age === 30 }).length, 1) | ||
var users3 = yield adapter.findAll(User, { name: 'John' }) | ||
assert.debug('findAll', { name: 'John' }) | ||
const users3 = await adapter.findAll(User, { name: 'John' }) | ||
assert.debug('found', JSON.stringify(users3, null, 2)) | ||
assert.equalObjects(users3, []) | ||
assert.equal(users3.length, 0) | ||
var users4 = yield adapter.findAll(User, { name: 'Johnny' }) | ||
assert.debug('findAll', { name: 'Johnny' }) | ||
const users4 = await adapter.findAll(User, { name: 'Johnny' }) | ||
assert.debug('found', JSON.stringify(users4, null, 2)) | ||
users4.sort(function (a, b) { | ||
@@ -49,4 +65,4 @@ return a.age - b.age | ||
assert.equal(users4[0].name, 'Johnny') | ||
assert.equal(users4.filter(function (x) { return x.id === userId1 }).length, 1) | ||
assert.equal(users4.filter(function (x) { return x.id === userId2 }).length, 1) | ||
assert.equal(users4.filter(function (x) { return x[User.idAttribute] === userId1 }).length, 1) | ||
assert.equal(users4.filter(function (x) { return x[User.idAttribute] === userId2 }).length, 1) | ||
assert.equal(users4.filter(function (x) { return x.age === 20 }).length, 1) | ||
@@ -53,0 +69,0 @@ assert.equal(users4.filter(function (x) { return x.age === 30 }).length, 1) |
module.exports = { | ||
devtool: 'source-map', | ||
entry: './src/index.js', | ||
@@ -13,9 +14,6 @@ output: { | ||
exclude: /(node_modules|bower_components)/, | ||
loader: 'babel', | ||
query: { | ||
presets: ['es2015'] | ||
} | ||
loader: 'babel' | ||
} | ||
] | ||
} | ||
}; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
17
166522
10
1945