Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
Added general workflow test with common queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubhomoly committed Mar 3, 2017
1 parent 5c6a99b commit 2e70d93
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/features/general.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,46 @@ test.serial('common workflow with indexes', async () => {
await Car.getStorage().dropIndex('Car#findByBrand')
await Car.getStorage().dropIndex('Settee#docType')
})

test('common queries', async () => {
// We're in the market for a new car ...
const CarSchema = new Schema('Car', {
brand: Type.string(),
color: Type.string()
})

const Car = settee.registerSchema(CarSchema)

let bmw = Car.create({
brand: 'BMW',
color: 'blue'
})

let audi = await Car.create({
brand: 'Audi',
color: 'red'
})

// query builder is scoped to 'Car' docType
let queryBuilder = Car.q({
consistency: settee.consistency.REQUEST_PLUS
})

// get all cars
await queryBuilder.all()
.should.eventually.have.lengthOf(2)

// get the count of all cars
await queryBuilder.count()
.should.eventually.eq(2)

// let's get a BMW with the first() method
let retrievedBmw = await queryBuilder.where('brand', 'BMW').first()

retrievedBmw.brand.should.eq('BMW')
retrievedBmw.color.should.eq('blue')

// let's delete the entry
await retrievedBmw.delete()
await audi.delete()
})

0 comments on commit 2e70d93

Please sign in to comment.