Skip to content

Commit

Permalink
adds tests for contexthash and defaults for created/lastupdated prope…
Browse files Browse the repository at this point in the history
…rties(current timestamp)
  • Loading branch information
anmolarora1 committed Nov 2, 2020
1 parent 6c64912 commit dd5e556
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/util/__tests__/importRoam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ import {
import {
exportContext,
} from '../../selectors'
import { importRoam } from '../importRoam'
import { importRoam } from '../importROAM'
import { State, initialState } from '../initialState'
import { RoamPage } from 'roam'
import { removeRoot } from '../../test-helpers/removeRoot'
import { SimplePath } from '../../types'
import { timestamp } from '../timestamp'

jest.mock('../timestamp', () => ({
timestamp: () => '2020-11-02T01:11:58.869Z'
}))

const testState: State = {
...initialState(),
thoughts: {
Expand Down Expand Up @@ -226,9 +230,15 @@ test('it should save create-time as created property', () => {
const roamBlocks = testData.map(roamBlock => roamBlock.children).flat()

const {
contextIndexUpdates: contextIndex,
thoughtIndexUpdates: thoughtIndex,
} = importRoam(testState, RANKED_ROOT as SimplePath, testData)

Object.keys(contextIndex)
.forEach(contextHash => {
expect(contextIndex[contextHash].lastUpdated).toEqual('2020-11-02T01:11:58.869Z')
})

Object.keys(thoughtIndex)
// ignore root blocks (and =create-email thought)of Roam page since they won't have create/edit time
.filter(thoughtHash => {
Expand All @@ -241,3 +251,21 @@ test('it should save create-time as created property', () => {
})

})

test('it should set the created and lastUpdated properties as current timestamp for root blocks', () => {
const {
thoughtIndexUpdates: thoughtIndex,
} = importRoam(testState, RANKED_ROOT as SimplePath, testData)

Object.keys(thoughtIndex)
// ignore root blocks (and =create-email thought)of Roam page since they won't have create/edit time
.filter(thoughtHash => {
const value = thoughtIndex[thoughtHash].value
return value === 'Fruits' || value === 'Veggies'
})
.forEach(thoughtHash => {
expect(thoughtIndex[thoughtHash].created).toEqual('2020-11-02T01:11:58.869Z')
expect(thoughtIndex[thoughtHash].lastUpdated).toEqual('2020-11-02T01:11:58.869Z')
})

})

0 comments on commit dd5e556

Please sign in to comment.