it('Bone.hasMany', async function() { const post = await Post.first.with('comments'); expect(post.comments.length).to.be.above(0); expect(post.comments[0]).to.be.a(Comment); expect(post.comments.map(comment => comment.content).sort()).to.eql(comments.sort()); });
it('bone.save() should UPDATE when primaryKey is defined and saved before', async function() { const post = await Post.create({ id: 1, title: 'New Post', createdAt: new Date(2010, 9, 11) }); const updatedAtWas = post.updatedAt; post.title = 'Skeleton King'; await post.save(); const foundPost = await Post.findOne({ title: 'Skeleton King' }); expect(foundPost.id).to.equal(post.id); expect(foundPost.updatedAt.getTime()).to.be.above(updatedAtWas.getTime()); });
describe('list reserved capacity should ok', function () { const client = new FunctionComputeClient(ACCOUNT_ID, { accessKeyID: ACCESS_KEY_ID, accessKeySecret: ACCESS_KEY_SECRET, region: 'cn-shanghai' }); it('listReservedCapacities should ok', async function () { const response = await client.listReservedCapacities(); expect(response.data).to.be.ok(); expect(response.data.reservedCapacities).to.be.ok(); for (var i = 0; i < response.data.reservedCapacities.length; i++) { const elem = response.data.reservedCapacities[i]; expect(elem.instanceId.length).to.be.equal(22); expect(elem.cu).to.be.above(0); expect(elem.Deadline > elem.CreatedTime).to.be.true; expect(elem).to.have.property('lastModifiedTime'); expect(elem).to.have.property('isRefunded'); } }); });
it('Bone.update(where, values)', async function() { const post = await Post.create({ title: 'New Post', createdAt: new Date(2010, 9, 11) }); await Post.update({ title: 'New Post' }, { title: 'Skeleton King' }); const foundPost = await Post.findOne({ title: 'Skeleton King' }); expect(await Post.findOne({ title: 'New Post' })).to.be(null); expect(foundPost.id).to.equal(post.id); expect(foundPost.updatedAt.getTime()).to.be.above(post.updatedAt.getTime()); });
it('.with({ ...names })', async function() { const post = await Post.first.with({ attachment: {}, comments: { select: 'id, content' }, tags: {} }); expect(post.tags[0]).to.be.a(Tag); expect(post.tagMaps[0]).to.be.a(TagMap); expect(post.attachment).to.be.a(Attachment); expect(post.comments.length).to.be.above(0); expect(post.comments[0].id).to.be.ok(); // because createdAt is not selected expect(() => post.comments[0].createdAt).to.throwException(); expect(post.comments.map(comment => comment.content).sort()).to.eql(comments.sort()); });
it('.find $lt', async function() { const posts = await Post.find({ id: { $lt: 100 }}, { limit: 10 }); expect(posts.length).to.be.above(0); expect(posts[0].id).to.be.below(100); });
expect(post.id).to.be.above(0); const foundPost = await Post.findOne({}); expect(foundPost.id).to.equal(post.id);
it('.find $eq', async function() { const posts = await Post.find({ title: { $eq: 'New Post' } }); expect(posts.length).to.be.above(0); expect(posts[0].title).to.equal('New Post'); });
it('.find $notBetween', async function() { const post = await Post.findOne({ id: { $notBetween: [1, 2] }}); expect(post.id).to.be.above(2); });
it('.find $between', async function() { const post = await Post.findOne({ id: { $between: [90, 100] }}); expect(post.id).to.be.above(90); expect(post.id).to.be.below(100); });
it('.find $lte', async function() { const posts = await Post.find({ id: { $lte: 99 }}, { limit: 10 }); expect(posts.length).to.be.above(0); expect(posts[0].id).to.be.below(100); });