Skip to content

Commit

Permalink
Merge afb4c79 into 2a14f4d
Browse files Browse the repository at this point in the history
  • Loading branch information
lilsweetcaligula committed May 20, 2021
2 parents 2a14f4d + afb4c79 commit f3173b5
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,56 @@ function basictest(settings) {
})
})

describe('when the id$ arg passed to #save$ is undefined', function () {
it('should generate a new id and save the entity', function (done) {
si.make('foo')
.data$({ p1: 'v1', p2: 'v2' })
.save$({ id$: undefined }, function (err, foo1) {
if (err) {
return done(err)
}

expect(typeof foo1.id).to.equal('string')

foo1.load$(
foo1.id,
verify(done, function (foo2) {
expect(foo2).not.to.be.null()
expect(foo2).not.to.be.undefined()

expect(foo2.p1).to.equal('v1')
expect(foo2.p2).to.equal('v2')
})
)
})
})
})

describe('when the id$ arg passed to #save$ is null', function () {
it('should generate a new id and save the entity', function (done) {
si.make('foo')
.data$({ p1: 'v1', p2: 'v2' })
.save$({ id$: null }, function (err, foo1) {
if (err) {
return done(err)
}

expect(typeof foo1.id).to.equal('string')

foo1.load$(
foo1.id,
verify(done, function (foo2) {
expect(foo2).not.to.be.null()
expect(foo2).not.to.be.undefined()

expect(foo2.p1).to.equal('v1')
expect(foo2.p2).to.equal('v2')
})
)
})
})
})

it('should update an entity if id provided', function (done) {
var foo = si.make('foo')
foo.id = 'to-be-updated'
Expand Down Expand Up @@ -376,6 +426,56 @@ function basictest(settings) {
})
})

describe('when the provided id is null', function () {
it('should generate a new id and save the entity', function (done) {
si.make('foo')
.data$({ id: null, p1: 'v1', p2: 'v2' })
.save$(function (err, foo1) {
if (err) {
return done(err)
}

expect(typeof foo1.id).to.equal('string')

foo1.load$(
foo1.id,
verify(done, function (foo2) {
expect(foo2).not.to.be.null()
expect(foo2).not.to.be.undefined()

expect(foo2.p1).to.equal('v1')
expect(foo2.p2).to.equal('v2')
})
)
})
})
})

describe('when the provided id is undefined', function () {
it('should generate a new id and save the entity', function (done) {
si.make('foo')
.data$({ id: undefined, p1: 'v1', p2: 'v2' })
.save$(function (err, foo1) {
if (err) {
return done(err)
}

expect(typeof foo1.id).to.equal('string')

foo1.load$(
foo1.id,
verify(done, function (foo2) {
expect(foo2).not.to.be.null()
expect(foo2).not.to.be.undefined()

expect(foo2.p1).to.equal('v1')
expect(foo2.p2).to.equal('v2')
})
)
})
})
})

it("should save an entity if id provided but original doesn't exist", function (done) {
var foo = si.make('foo')
foo.id = 'will-be-inserted'
Expand Down

0 comments on commit f3173b5

Please sign in to comment.