diff --git a/__tests__/localJsonStoreAgent.test.ts b/__tests__/localJsonStoreAgent.test.ts index 2bdb9c341..b4589549a 100644 --- a/__tests__/localJsonStoreAgent.test.ts +++ b/__tests__/localJsonStoreAgent.test.ts @@ -77,6 +77,7 @@ import messageHandler from './shared/messageHandler' import utils from './shared/utils' import { JsonFileStore } from './utils/json-file-store' import credentialStatus from './shared/credentialStatus' +import dbInitOptions from "./shared/dbInitOptions"; jest.setTimeout(120000) @@ -238,4 +239,5 @@ describe('Local json-data-store integration tests', () => { didCommPacking(testContext) utils(testContext) credentialStatus(testContext) + dbInitOptions(testContext) }) diff --git a/__tests__/shared/dbInitOptions.ts b/__tests__/shared/dbInitOptions.ts index ccd63f1d9..7ee289f9b 100644 --- a/__tests__/shared/dbInitOptions.ts +++ b/__tests__/shared/dbInitOptions.ts @@ -201,6 +201,53 @@ export default (testContext: { }) expect(retrievedCredential.length).toBeGreaterThan(0) }) + + it('should delete credentials without clearing the claims table', async () => { + const credA = await agent.createVerifiableCredential({ + proofFormat: 'jwt', + credential: { + type: ['Important'], + credentialSubject: { + important: 'yes', + serious: true, + }, + issuer: identifier.did, + }, + }) + const credB = await agent.createVerifiableCredential({ + proofFormat: 'jwt', + credential: { + type: ['Unimportant'], + credentialSubject: { + bla: 'bla', + }, + issuer: identifier.did, + }, + }) + + const credAhash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential: credA }) + const credBhash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential: credB }) + + const queryBeforeDelete = await agent.dataStoreORMGetVerifiableCredentialsByClaims({ + where: [ + { column: 'type', value: ['important'] }, + { column: 'value', value: ['yes'] }, + ], + }) + expect(queryBeforeDelete.length).toBeGreaterThan(0) + expect(queryBeforeDelete[0].hash).toEqual(credAhash) + + await agent.dataStoreDeleteVerifiableCredential({ hash: credBhash }) + + const queryAfterDelete = await agent.dataStoreORMGetVerifiableCredentialsByClaims({ + where: [ + { column: 'type', value: ['important'] }, + { column: 'value', value: ['yes'] }, + ], + }) + expect(queryAfterDelete.length).toBeGreaterThan(0) + expect(queryAfterDelete[0].hash).toEqual(credAhash) + }) }) } }) diff --git a/packages/data-store/src/data-store.ts b/packages/data-store/src/data-store.ts index b13f24ad7..845797910 100644 --- a/packages/data-store/src/data-store.ts +++ b/packages/data-store/src/data-store.ts @@ -98,7 +98,7 @@ export class DataStore implements IAgentPlugin { const claims = await (await getConnectedDb(this.dbConnection)) .getRepository(Claim) - .find({ where: { credential: { id: credentialEntity.id } } as any }) + .find({ where: { credential: { hash: credentialEntity.hash } } }) await (await getConnectedDb(this.dbConnection)).getRepository(Claim).remove(claims)