Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set updateAt on records when updating a record #1272

Merged
merged 13 commits into from
Feb 10, 2023
21 changes: 21 additions & 0 deletions packages/core/src/storage/__tests__/IndyStorageService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type * as Indy from 'indy-sdk'
import { agentDependencies, getAgentConfig, getAgentContext } from '../../../tests/helpers'
import { SigningProviderRegistry } from '../../crypto/signing-provider'
import { RecordDuplicateError, RecordNotFoundError } from '../../error'
import { sleep } from '../../utils/sleep'
import { IndyWallet } from '../../wallet/IndyWallet'
import { IndyStorageService } from '../IndyStorageService'

Expand Down Expand Up @@ -113,6 +114,13 @@ describe('IndyStorageService', () => {

expect(record).toEqual(found)
})

it('After a save the record should have update the updatedAt property', async () => {
const time = new Date().getTime()
await sleep(1000)
const record = await insertRecord({ id: 'test-updatedAt' })
expect(record.updatedAt?.getTime()).toBeGreaterThan(time)
})
KolbyRKunz marked this conversation as resolved.
Show resolved Hide resolved
})

describe('getById()', () => {
Expand Down Expand Up @@ -151,6 +159,19 @@ describe('IndyStorageService', () => {
const retrievedRecord = await storageService.getById(agentContext, TestRecord, record.id)
expect(retrievedRecord).toEqual(record)
})

it('After a record has been updated it should have updated the updatedAT property', async () => {
const time = new Date()
await sleep(1000)
const record = await insertRecord({ id: 'test-id' })

record.replaceTags({ ...record.getTags(), foo: 'bar' })
record.foo = 'foobaz'
await storageService.update(agentContext, record)

const retrievedRecord = await storageService.getById(agentContext, TestRecord, record.id)
expect(retrievedRecord.createdAt.getTime()).toBeGreaterThan(time.getTime())
})
})

describe('delete()', () => {
Expand Down