Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
json -> obj
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisfosterelli committed Jul 12, 2016
1 parent f66429f commit be50816
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/test/entry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,24 @@ test('set timezone offset', t => {
test('created date added to entry', t => {
const today = new Date()
const e = new Entry(userId, '8am-5pm working on things')
const json = e.toObject()
const obj = e.toObject()

t.ok(e.ref, 'ref is set')
t.ok(moment(today).isSame(e.ref, 'second'), 'ref date is today')
t.ok(json.ref, 'ref is set on json')
t.ok(moment(today).isSame(json.ref, 'second'), 'json.ref date is today')
t.ok(obj.ref, 'ref is set on object')
t.ok(moment(today).isSame(obj.ref, 'second'), 'obj.ref date is today')
t.end()
})

test('passed reference date added to entry', t => {
const date = new Date(2016, 0, 1, 12, 15, 30) // Jan 1, 2016 12:15:30
const e = new Entry(userId, '8am-5pm working on things', {date})
const json = e.toObject()
const obj = e.toObject()

t.ok(e.ref, 'ref is set')
t.ok(moment(date).isSame(e.ref, 'second'), 'ref date is Jan 1')
t.ok(json.ref, 'ref is set on json')
t.ok(moment(date).isSame(json.ref, 'second'), 'json.ref date is Jan 1')
t.ok(obj.ref, 'ref is set on object')
t.ok(moment(date).isSame(obj.ref, 'second'), 'obj.ref date is Jan 1')
t.end()
})

Expand Down Expand Up @@ -210,32 +210,32 @@ test('parsed time string is present', t => {
t.end()
})

test('toObject() returns a json obj', t => {
test('toObject() returns an object', t => {
const e = new Entry(userId, '8am-10am worked on some things #tag1 #tag2')

const json = e.toObject()
t.equals(json.message, '8am-10am worked on some things #tag1 #tag2', 'message')
t.ok(json.hasDates, 'hasDates')
t.equals(e.start, json.start, 'start')
t.equals(e.end, json.end, 'end')
t.equals(json.duration.seconds, 2*60*60, 'duration seconds')
t.equals(json.time, e.time, 'time')
t.equals(json._id, e._id, '_id')
t.equals(json.version, version, 'version')
t.deepEquals(json.tags, [...e.tags], 'tags array')
t.ok(moment.utc(json.startArr).isSame(json.start), 'start and startArr are same date')
t.ok(moment.utc(json.endArr).isSame(json.end), 'end and endArr are same date')
t.ok(json.startArr instanceof Array, 'startArr is an array')
t.ok(json.endArr instanceof Array, 'endArr is an array')
const obj = e.toObject()
t.equals(obj.message, '8am-10am worked on some things #tag1 #tag2', 'message')
t.ok(obj.hasDates, 'hasDates')
t.equals(e.start, obj.start, 'start')
t.equals(e.end, obj.end, 'end')
t.equals(obj.duration.seconds, 2*60*60, 'duration seconds')
t.equals(obj.time, e.time, 'time')
t.equals(obj._id, e._id, '_id')
t.equals(obj.version, version, 'version')
t.deepEquals(obj.tags, [...e.tags], 'tags array')
t.ok(moment.utc(obj.startArr).isSame(obj.start), 'start and startArr are same date')
t.ok(moment.utc(obj.endArr).isSame(obj.end), 'end and endArr are same date')
t.ok(obj.startArr instanceof Array, 'startArr is an array')
t.ok(obj.endArr instanceof Array, 'endArr is an array')

t.end()
})

test('fromObject() will create an Entry from existing document', t => {
const date = new Date('Jan 25, 2015 0:00:00')
const existing = new Entry(userId, '8am-10am worked on things #tag1 #tag2', {date})
const json = existing.toObject()
const e = Entry.fromObject(json)
const obj = existing.toObject()
const e = Entry.fromObject(obj)

t.equals(existing._id, e._id, '_id matches')
t.equals(existing.version, e.version, 'version matches')
Expand Down

0 comments on commit be50816

Please sign in to comment.