Skip to content

Commit

Permalink
test: adding more complete test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Barrior committed Nov 26, 2019
1 parent 6d9e8e2 commit c7c07c7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/api-object-form.ts
Expand Up @@ -163,3 +163,36 @@ test('Check "select" parameter', async () => {
const ace3: any = await Dog.findById(ace.id, 'name_modifiedAt')
isDateTypeAndValueValid(ace3.name_modifiedAt, { startTime, endTime })
})

test('key type is not function should be ignored', async () => {
const schema = new mongoose.Schema({
name: String,
age: Number,
// 1: in purchasing, 2: bought, 3: sold
status: Number,
})

schema.plugin(modifiedAt, {
async boughtAt() {
await P.delay(1000)
return false
},
soldAt: true,
})

const Dog = mongoose.model(randomName(), schema)

const jack: any = await Dog.create({
name: 'Jack',
age: 1,
status: 1,
})

expect(jack.boughtAt).toBeUndefined()
expect(jack.soldAt).toBeUndefined()

jack.status = 2
await jack.save()
expect(jack.boughtAt).toBeUndefined()
expect(jack.soldAt).toBeUndefined()
})

0 comments on commit c7c07c7

Please sign in to comment.