Skip to content

Commit

Permalink
fix: refactored UniformCredential names to digitalCredential, added u…
Browse files Browse the repository at this point in the history
…tility methods for getting the credential document type
  • Loading branch information
sksadjad committed Feb 28, 2024
1 parent cf67a50 commit a0c5530
Show file tree
Hide file tree
Showing 22 changed files with 582 additions and 448 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { DataSource } from 'typeorm'
import { DataStoreDigitalCredentialEntities } from '../index'
import { DataStoreDigitalCredentialMigrations } from '../migrations'
import { DigitalCredentialEntity } from '../entities/digitalCredential/DigitalCredentialEntity'
import {
CredentialCorrelationType,
CredentialDocumentFormat,
CredentialType,
NonPersistedDigitalCredential
} from '../types/digitalCredential/digitalCredential'
import { computeEntryHash } from '@veramo/utils'
import { AddDigitalCredentialArgs } from '../types/digitalCredential/IAbstractDigitalCredentialStore'
import {nonPersistedDigitalCredentialEntityFromAddArgs} from "../utils/digitalCredential/MappingUtils";

describe('Database entities tests', (): void => {
let dbConnection: DataSource

beforeEach(async (): Promise<void> => {
dbConnection = await new DataSource({
type: 'sqlite',
database: ':memory:',
//logging: 'all',
migrationsRun: false,
migrations: DataStoreDigitalCredentialMigrations,
synchronize: false,
entities: [...DataStoreDigitalCredentialEntities],
}).initialize()
await dbConnection.runMigrations()
expect(await dbConnection.showMigrations()).toBeFalsy()
})

afterEach(async (): Promise<void> => {
await (await dbConnection).destroy()
})

it('should save digital credential to database', async (): Promise<void> => {
const rawCredential: string =
'eyJraWQiOiJkaWQ6a2V5Ono2TWtyaGt5M3B1c20yNk1laUZhWFUzbjJuZWtyYW13RlVtZ0dyZUdHa0RWNnpRaiN6Nk1rcmhreTNwdXNtMjZNZWlGYVhVM24ybmVrcmFtd0ZVbWdHcmVHR2tEVjZ6UWoiLCJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vc3BoZXJlb24tb3BlbnNvdXJjZS5naXRodWIuaW8vc3NpLW1vYmlsZS13YWxsZXQvY29udGV4dC9zcGhlcmVvbi13YWxsZXQtaWRlbnRpdHktdjEuanNvbmxkIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJTcGhlcmVvbldhbGxldElkZW50aXR5Q3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJmaXJzdE5hbWUiOiJTIiwibGFzdE5hbWUiOiJLIiwiZW1haWxBZGRyZXNzIjoic0BrIn19LCJzdWIiOiJ1cm46dXVpZDpkZGE3YmYyNC04ZTdhLTQxZjgtYjY2Yy1hNDhkYmM1YjEwZmEiLCJqdGkiOiJ1cm46dXVpZDpkZGE3YmYyNC04ZTdhLTQxZjgtYjY2Yy1hNDhkYmM1YjEwZmEiLCJuYmYiOjE3MDg0NDA4MDgsImlzcyI6ImRpZDprZXk6ejZNa3Joa3kzcHVzbTI2TWVpRmFYVTNuMm5la3JhbXdGVW1nR3JlR0drRFY2elFqIn0.G0M84XVAxSmzGY-NQuB9NBofNrINSn6lvxW6761Vlq6ypvYgtc2xNdpiRmw8ryVNfnpzrr4Z5cB1RlrC05rJAw'
const digitalCredential: AddDigitalCredentialArgs = {
raw: rawCredential,
issuerCorrelationType: CredentialCorrelationType.DID,
subjectCorrelationType: CredentialCorrelationType.DID,
issuerCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
}

const digitalCredentialEntity: NonPersistedDigitalCredential = nonPersistedDigitalCredentialEntityFromAddArgs(digitalCredential)
const fromDb: DigitalCredentialEntity = await dbConnection.getRepository(DigitalCredentialEntity).save(digitalCredentialEntity)
expect(fromDb).toBeDefined()
expect(fromDb?.id).not.toBeNull()
expect(fromDb?.credentialType).toEqual(CredentialType.C)
expect(fromDb?.documentFormat).toEqual(CredentialDocumentFormat.JWT)
expect(fromDb?.raw).toEqual(rawCredential)
expect(fromDb?.hash).toEqual(computeEntryHash(rawCredential))
expect(fromDb?.issuerCorrelationType).toEqual(CredentialCorrelationType.DID)
expect(fromDb?.subjectCorrelationType).toEqual(CredentialCorrelationType.DID)
expect(fromDb?.issuerCorrelationId).toEqual('did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj')
expect(fromDb?.subjectCorrelationId).toEqual('did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj')
expect(fromDb?.tenantId).toEqual('urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj')
})

it('should assign correct values to DigitalCredential', () => {
const digitalCredential: NonPersistedDigitalCredential = nonPersistedDigitalCredentialEntityFromAddArgs({
raw: 'eyJraWQiOiJkaWQ6a2V5Ono2TWtyaGt5M3B1c20yNk1laUZhWFUzbjJuZWtyYW13RlVtZ0dyZUdHa0RWNnpRaiN6Nk1rcmhreTNwdXNtMjZNZWlGYVhVM24ybmVrcmFtd0ZVbWdHcmVHR2tEVjZ6UWoiLCJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vc3BoZXJlb24tb3BlbnNvdXJjZS5naXRodWIuaW8vc3NpLW1vYmlsZS13YWxsZXQvY29udGV4dC9zcGhlcmVvbi13YWxsZXQtaWRlbnRpdHktdjEuanNvbmxkIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJTcGhlcmVvbldhbGxldElkZW50aXR5Q3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJmaXJzdE5hbWUiOiJTIiwibGFzdE5hbWUiOiJLIiwiZW1haWxBZGRyZXNzIjoic0BrIn19LCJzdWIiOiJ1cm46dXVpZDpkZGE3YmYyNC04ZTdhLTQxZjgtYjY2Yy1hNDhkYmM1YjEwZmEiLCJqdGkiOiJ1cm46dXVpZDpkZGE3YmYyNC04ZTdhLTQxZjgtYjY2Yy1hNDhkYmM1YjEwZmEiLCJuYmYiOjE3MDg0NDA4MDgsImlzcyI6ImRpZDprZXk6ejZNa3Joa3kzcHVzbTI2TWVpRmFYVTNuMm5la3JhbXdGVW1nR3JlR0drRFY2elFqIn0.G0M84XVAxSmzGY-NQuB9NBofNrINSn6lvxW6761Vlq6ypvYgtc2xNdpiRmw8ryVNfnpzrr4Z5cB1RlrC05rJAw',
issuerCorrelationType: CredentialCorrelationType.DID,
subjectCorrelationType: CredentialCorrelationType.DID,
issuerCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
})
expect(digitalCredential.credentialType).toEqual(CredentialType.C)
expect(digitalCredential.createdAt).toEqual(new Date())
})
})
Loading

0 comments on commit a0c5530

Please sign in to comment.