Skip to content

Commit

Permalink
fix: open handles and logging after test completes
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Nov 25, 2021
1 parent 8a28147 commit 8cca899
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:schema-api": "lerna run extract-api && lerna run generate-plugin-schema",
"bootstrap": "lerna bootstrap",
"test:ci": "jest --config=jest.json",
"test": "jest --verbose --config=jest.json --coverage=true",
"test": "jest --verbose --config=jest.json --coverage=true --detectOpenHandles",
"test:watch": "yarn test --watch --verbose",
"prettier": "prettier --write \"{packages,__tests__,!dist}/**/*.{ts,js,json,md,yml}\"",
"build-clean": "rimraf ./packages/*/dist ./packages/*/api ./packages/*/node_modules ./packages/*/tsconfig.tsbuildinfo && jest --clearCache",
Expand Down
2 changes: 1 addition & 1 deletion packages/lto-did-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "tsc --build"
},
"dependencies": {
"@sphereon/lto-did-ts": "^0.1.4",
"@sphereon/lto-did-ts": "^0.1.6",
"lto-api": "^0.5.14",
"@sphereon/did-uni-client": "^0.3.3",
"@sphereon/ssi-sdk-core": "^0.0.1",
Expand Down
35 changes: 18 additions & 17 deletions packages/lto-did-provider/src/__tests__/lto-did-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ describe('@sphereon/lto-did-provider', () => {
} as IKeyManager,
} as IRequiredContext

it('should create identifier', async () => {
it('should create identifier', () => {
const restResponse = {
data: {
didIdentifier: 'TestDID',
},
}

// jest.spyOn(fetch, '').mockResolvedValueOnce(Promise.resolve(restResponse));
const identifier = await ltoDIDProvider.createIdentifier(
const identifier = ltoDIDProvider.createIdentifier(
{
options: {
privateKeyHex: PRIVATE_KEY_HEX,
Expand All @@ -74,13 +74,13 @@ describe('@sphereon/lto-did-provider', () => {
mockContext
)

/*expect(provider).not.toHaveProperty('resolveDid')
expect(axios.post).toHaveBeenCalledWith(`${AppConfig.credencoBackendUrl}/did`, {"publicKeyBase58": "0xmyPublicKey"}, {"headers": {"Content-Type": "application/json"}});*/
assertExpectedIdentifier(identifier)

expect.assertions(4)
return assertExpectedIdentifier(identifier)
})

it('should create identifier with verificationMethods', async () => {
const identifier = await ltoDIDProvider.createIdentifier(
const identifier = ltoDIDProvider.createIdentifier(
{
options: {
privateKeyHex: PRIVATE_KEY_HEX,
Expand All @@ -90,13 +90,13 @@ describe('@sphereon/lto-did-provider', () => {
mockContext
)

assertExpectedIdentifier(identifier)
return assertExpectedIdentifier(identifier)
})

it('should properly import identifier using DID manager', async () => {
const importedIdentifier = await didManager.didManagerImport(IDENTIFIER, mockContext)
assertExpectedIdentifier(importedIdentifier)
assertExpectedIdentifier(await didManager.didManagerGet({ did: LTO_DID }))
const importedIdentifier = didManager.didManagerImport(IDENTIFIER, mockContext)
await assertExpectedIdentifier(importedIdentifier)
return assertExpectedIdentifier(didManager.didManagerGet({ did: LTO_DID }))
})

it('should add verification key', async () => {
Expand All @@ -106,7 +106,8 @@ describe('@sphereon/lto-did-provider', () => {
DIDService.prototype.addVerificationMethod = mockAddVerificationMethod
mockAddVerificationMethod.mockReturnValue(Promise.resolve({ address }))

const result = await ltoDIDProvider.addKey(
await expect(
ltoDIDProvider.addKey(
{
identifier: {
...IDENTIFIER,
Expand All @@ -120,7 +121,7 @@ describe('@sphereon/lto-did-provider', () => {
mockContext
)

expect(result).toEqual(`did:lto:${address}#key`)
).resolves.toEqual(`did:lto:${address}#key`)

// jest.resetAllMocks();
})
Expand Down Expand Up @@ -193,16 +194,16 @@ describe('@sphereon/lto-did-provider', () => {
})
})

function assertExpectedIdentifier(identifier: Omit<IIdentifier, 'provider'>) {
expect(identifier).toHaveProperty('did', LTO_DID)
expect(identifier).toHaveProperty('controllerKeyId', LTO_KID)
expect(identifier).toHaveProperty('keys', [
async function assertExpectedIdentifier(identifier: Promise<Omit<IIdentifier, 'provider'>>) {
await expect(identifier).resolves.toHaveProperty('did', LTO_DID)
await expect(identifier).resolves.toHaveProperty('controllerKeyId', LTO_KID)
await expect(identifier).resolves.toHaveProperty('keys', [
{
kid: LTO_KID,
kms: 'local',
type: 'Ed25519',
publicKeyHex: PUBLIC_KEY_HEX,
},
])
expect(identifier).toHaveProperty('services', [])
return expect(identifier).resolves.toHaveProperty('services', [])
}
4 changes: 2 additions & 2 deletions packages/lto-did-provider/src/lto-did-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export class LtoDidProvider extends AbstractIdentifierProvider {
context: IRequiredContext
): Promise<Omit<IIdentifier, 'provider'>> {
if (this.isUniRegistrarMode()) {
return await this.createIdentifierUsingUniRegistrar(context, kms, options)
return this.createIdentifierUsingUniRegistrar(context, kms, options)
} else {
return await this.createIdentifierUsingNodeRPC(context, kms, options)
return this.createIdentifierUsingNodeRPC(context, kms, options)
}
}

Expand Down
31 changes: 16 additions & 15 deletions packages/vc-api-issuer/__tests__/shared/vcApiIssuerAgentLogic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TAgent } from '@veramo/core';
import { IVcApiIssuer } from '../../src/types/IVcApiIssuer';
import { TAgent } from '@veramo/core'
import { IVcApiIssuer } from '../../src/types/IVcApiIssuer'

type ConfiguredAgent = TAgent<IVcApiIssuer>;

Expand All @@ -9,14 +9,17 @@ export default (testContext: {
tearDown: () => Promise<boolean>;
}) => {
describe('Issuer Agent Plugin', () => {
let agent: ConfiguredAgent;
let agent: ConfiguredAgent

beforeAll(() => {
testContext.setup();
agent = testContext.getAgent();
});
beforeAll(async () => {
await testContext.setup()
agent = testContext.getAgent()
})

afterAll(testContext.tearDown);
afterAll(async () => {
await new Promise<void>(resolve => setTimeout(() => resolve(), 5000)); // avoid jest open handle error
await testContext.tearDown()
})

it('should issue', async () => {
const credential = {
Expand All @@ -42,13 +45,11 @@ export default (testContext: {
issuanceDate: '2020-03-16T22:37:26.544Z',
issuer: 'did:example:123',
type: ['VerifiableCredential', 'UniversityDegreeCredential'],
};
}

const result = await agent.issueCredentialUsingVcApi({
return await expect(agent.issueCredentialUsingVcApi({
credential,
});

expect(result.proof).not.toBeNull();
});
});
})).resolves.not.toBeNull()
})
})
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2098,10 +2098,10 @@
cross-fetch "^3.1.4"
did-resolver "^3.1.2"

"@sphereon/lto-did-ts@^0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@sphereon/lto-did-ts/-/lto-did-ts-0.1.4.tgz#004f7a9bb983f63eb359472564c7cda75461dd6c"
integrity sha512-vyjTDwsGFdSVcWtjdTQUL1SODdtOv7pPjr1yHkwre4oeeA3XAa+tZzOcOiXthR3KrMOYr/T9zOvbJ11wfr6VZw==
"@sphereon/lto-did-ts@^0.1.6":
version "0.1.6"
resolved "https://registry.yarnpkg.com/@sphereon/lto-did-ts/-/lto-did-ts-0.1.6.tgz#1978c57447ffb7c4aaa2c86ba8953b591bcb08e4"
integrity sha512-8ncLpCPiMzDo5X3t/3A+T+P2vmPqcfmdnTrAvyIGkXVqHQFR9UHMzvd8NOR6EzkS65T4L9sRVwM7hMsU1cXRtw==
dependencies:
"@lto-network/lto-crypto" "^1.1.1"
"@lto-network/lto-transactions" "^1.2.12"
Expand Down

0 comments on commit 8cca899

Please sign in to comment.