Skip to content

Commit

Permalink
Merge pull request #76 from shekhar-shubhendu/master
Browse files Browse the repository at this point in the history
fixed the failing tests
  • Loading branch information
jernejpregelj authored Oct 25, 2018
2 parents 1708937 + a0f807c commit 73ed441
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions test/test_orm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ test('Create asset with data', t => {
.then(res => t.deepEqual(res.data, expected))
})

test('Create asset with user provided id', t => {
const expected = { key: 'dataValue' }
const id = 'My-Unique-ID'
const bdbOrm = new Orm('http://localhost:9984/api/v1/', {
app_id: '',
app_key: ''
})
bdbOrm.define('myModel', 'https://schema.org/v1/myModel')
// create a public and private key for Alice
const aliceKeypair = new bdbOrm.driver.Ed25519Keypair()
return bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: expected
}, id)
.then(res => t.deepEqual(res.data, expected))
})

test('Retrieve asset', t => {
const expected = { key: 'dataValue' }

Expand All @@ -41,23 +59,23 @@ test('Retrieve asset', t => {
.then(res => t.deepEqual(res[0].data, expected))
})

test('Retrieve multiple asset', t => {
const expected = { key: 'dataValue' }

test('Retrieve multiple asset', async (t) => {
const bdbOrm = new Orm('http://localhost:9984/api/v1/', {
app_id: '',
app_key: ''
})
bdbOrm.define('myModel', 'https://schema.org/v1/myModel')
bdbOrm.define('myNewModel', 'https://schema.org/v1/myNewModel')
// create a public and private key for Alice
const aliceKeypair = new bdbOrm.driver.Ed25519Keypair()
return bdbOrm.models.myModel
const expected = await bdbOrm.models.myNewModel.retrieve().then(res => res.length) + 1

return bdbOrm.models.myNewModel
.create({
keypair: aliceKeypair,
data: { key: 'dataValue' }
})
.then(() => bdbOrm.models.myModel.retrieve()
.then(res => t.deepEqual(res[res.length - 1].data, expected)))
.then(() => bdbOrm.models.myNewModel.retrieve()
.then(res => t.deepEqual(res.length, expected)))
})

test('Append asset', t => {
Expand Down

0 comments on commit 73ed441

Please sign in to comment.