-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactored UniformCredential names to digitalCredential, added u…
…tility methods for getting the credential document type
- Loading branch information
Showing
22 changed files
with
582 additions
and
448 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
packages/data-store/src/__tests__/digitalCredential.entities.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
}) | ||
}) |
Oops, something went wrong.