@truestamp/client
Version:
## Description
59 lines (44 loc) • 1.79 kB
text/typescript
// Copyright © 2020-2023 Truestamp Inc. All rights reserved.
import { describe, test, expect } from 'vitest'
import { TruestampClient } from '../src/index'
import { dotenvLoad } from 'dotenv-mono'
dotenvLoad()
import { Commitment, CommitmentVerification } from 'types'
describe('getCommitment', () => {
const truestamp = new TruestampClient({
apiKey: process.env.TRUESTAMP_API_KEY ?? '',
apiBaseUrl: process.env.TRUESTAMP_API_BASE_URL,
})
test('returns a Commitment', async () => {
const r = await truestamp.getCommitment(process.env.TEST_ITEM_ID as string)
// throws if not valid
Commitment.parse(r)
expect(r).toHaveProperty('commitmentData')
expect(r).toHaveProperty('commitmentDataSignatures')
})
test('should throw with a clean error if the input is rejected by the server', async () => {
await expect(truestamp.getCommitment('foo')).rejects.toThrow(
'HTTP fetch error : 400 Bad Request : Bad Request : failed to decode provided ID foo',
)
})
})
describe('getCommitmentVerification', () => {
const truestamp = new TruestampClient({
apiKey: process.env.TRUESTAMP_API_KEY ?? '',
apiBaseUrl: process.env.TRUESTAMP_API_BASE_URL,
})
test('returns a CommitmentVerification', async () => {
const r = await truestamp.getCommitmentVerification(
process.env.TEST_ITEM_ID as string,
)
// throws if not valid
CommitmentVerification.parse(r)
expect(r).toHaveProperty('verified')
expect(r.verified).toBe(true)
})
test('should throw with a clean error if the input is rejected by the server', async () => {
await expect(truestamp.getCommitment('foo')).rejects.toThrow(
'HTTP fetch error : 400 Bad Request : Bad Request : failed to decode provided ID foo',
)
})
})