Skip to content

Commit

Permalink
adjust to modernise
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed May 25, 2020
1 parent 14997a9 commit 627461b
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ var barverify = function(bar) {
Assert.equal(bar.int, 11)
Assert.equal(bar.dec, 33.33)
Assert.equal(bar.bol, false)

Assert.equal(
isDate(bar.wen) ? bar.wen.toISOString() : bar.wen,
new Date(2020, 1, 1).toISOString()
)

Assert.equal('' + bar.arr, '' + [2, 3])
Assert.deepEqual(bar.obj, {
a: 1,
Expand Down Expand Up @@ -232,8 +234,11 @@ function basictest(settings) {
})
})



describe('Save', function() {
beforeEach(clearDb(si))

beforeEach(
createEntities(si, 'foo', [
{
Expand All @@ -244,7 +249,7 @@ function basictest(settings) {
}
])
)

it('should save an entity to store (and generate an id)', function(done) {
var foo = si.make('foo')
foo.p1 = 'v1'
Expand Down Expand Up @@ -296,6 +301,7 @@ function basictest(settings) {
foo.p2 = 'z2'
foo.p3 = 'v3'


foo.save$(function(err, foo1) {
Assert.isNull(err)
Assert.isNotNull(foo1.id)
Expand Down Expand Up @@ -345,6 +351,7 @@ function basictest(settings) {
})
})


it('should allow to not merge during update with merge$: false', function(done) {
var foo = si.make('foo')
foo.id = 'to-be-updated'
Expand All @@ -371,6 +378,7 @@ function basictest(settings) {
)
})
})


it('should support different attribute types', function(done) {
var bar = si.make(bartemplate)
Expand All @@ -395,6 +403,7 @@ function basictest(settings) {
})
})


it('should allow dublicate attributes', function(done) {
var foo = si.make('foo')
foo.p2 = 'v2'
Expand All @@ -417,6 +426,7 @@ function basictest(settings) {
})
})


it('should not save modifications to entity after save completes', function(done) {
var foo = si.make('foo')
foo.p3 = ['a']
Expand Down Expand Up @@ -454,26 +464,30 @@ function basictest(settings) {
}

foo1.p1 = null

// NOTE: undefined has no effect
foo1.p2 = undefined

foo1.save$(function(err, foo2) {
if (err) {
return done(err)
}

Assert.notOk(foo2.p1)
Assert.notOk(foo2.p2)
Assert.ok(foo2.p2)

foo.load$(
foo1.id,
verify(done, function(foo3) {
Assert.ok(foo3)
Assert.notOk(foo3.p1)
Assert.notOk(foo3.p2)
Assert.ok(foo3.p2)
})
)
})
})
})

})

describe('With Option merge:false', function() {
Expand All @@ -497,6 +511,7 @@ function basictest(settings) {
done()
})

/*
it('should update an entity if id provided', function(done) {
var foo = merge.make('foo')
foo.id = 'to-be-updated'
Expand All @@ -523,7 +538,8 @@ function basictest(settings) {
)
})
})

*/

it('should allow to merge during update with merge$: true', function(done) {
var foo = merge.make('foo')
foo.id = 'to-be-updated'
Expand Down Expand Up @@ -1362,6 +1378,7 @@ function sqltest(settings) {
})
})


return script
}

Expand Down

0 comments on commit 627461b

Please sign in to comment.