-
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.
feat: changed the test structure and few other pr notes addressed
- Loading branch information
Showing
17 changed files
with
286 additions
and
112 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions
44
packages/oid4vci-issuer-rest-client/__tests__/localAgent.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,44 @@ | ||
import { createObjects, getConfig } from '../../agent-config/dist' | ||
|
||
jest.setTimeout(30000) | ||
|
||
import issuanceRestClientAgentLogic from './shared/issuanceRestClientAgentLogic' | ||
import nock from 'nock' | ||
|
||
let agent: any | ||
|
||
const setup = async (): Promise<boolean> => { | ||
const config = await getConfig('packages/oid4vci-issuer-rest-client/agent.yml') | ||
const { localAgent } = await createObjects(config, { localAgent: '/agent' }) | ||
agent = localAgent | ||
nock('https://ssi-backend.sphereon.com/webapp/') | ||
.post(`/credential-offers`, { | ||
grants: { | ||
'urn:ietf:params:oauth:grant-type:pre-authorized_code': { | ||
'pre-authorized_code': '1234', | ||
user_pin_required: false, | ||
}, | ||
}, | ||
credentials: ['dbc2023'], | ||
}) | ||
.times(4) | ||
.reply(200, { | ||
uri: 'openid-credential-offer://?credential_offer=%7B%22grants%22%3A%7B%22urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Apre-authorized_code%22%3A%7B%22pre-authorized_code%22%3A%221234%22%2C%22user_pin_required%22%3Afalse%7D%7D%2C%22credentials%22%3A%5B%22dbc2023%22%5D%2C%22credential_issuer%22%3A%22https%3A%2F%2Fdbc2023.test.sphereon.com%2Fissuer%2Fdbc2023%22%7D', | ||
}) | ||
return true | ||
} | ||
|
||
const tearDown = async (): Promise<boolean> => { | ||
return true | ||
} | ||
|
||
const getAgent = () => agent | ||
const testContext = { | ||
getAgent, | ||
setup, | ||
tearDown, | ||
} | ||
|
||
describe('Local integration tests', () => { | ||
issuanceRestClientAgentLogic(testContext) | ||
}) |
67 changes: 67 additions & 0 deletions
67
packages/oid4vci-issuer-rest-client/__tests__/restAgent.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,67 @@ | ||
import 'cross-fetch/polyfill' | ||
// @ts-ignore | ||
import express, { Router } from 'express' | ||
import { Server } from 'http' | ||
import { IAgent, createAgent, IAgentOptions } from '@veramo/core' | ||
import { AgentRestClient } from '@veramo/remote-client' | ||
import { AgentRouter, RequestWithAgentRouter } from '@veramo/remote-server' | ||
import { createObjects, getConfig } from '../../agent-config/dist' | ||
import { IOID4VCIRestClient } from '../src' | ||
import issuanceRestClientAgentLogic from './shared/issuanceRestClientAgentLogic' | ||
|
||
jest.setTimeout(30000) | ||
|
||
const port = 3002 | ||
const basePath = '/agent' | ||
|
||
let serverAgent: IAgent | ||
let restServer: Server | ||
|
||
const getAgent = (options?: IAgentOptions) => | ||
createAgent<IOID4VCIRestClient>({ | ||
...options, | ||
plugins: [ | ||
new AgentRestClient({ | ||
url: 'http://localhost:' + port + basePath, | ||
enabledMethods: serverAgent.availableMethods(), | ||
schema: serverAgent.getSchema(), | ||
}), | ||
], | ||
}) | ||
|
||
const setup = async (): Promise<boolean> => { | ||
const config = await getConfig('packages/oid4vci-issuer-rest-client/agent.yml') | ||
const { agent } = await createObjects(config, { agent: '/agent' }) | ||
serverAgent = agent | ||
|
||
const agentRouter: Router = AgentRouter({ | ||
exposedMethods: serverAgent.availableMethods(), | ||
}) | ||
|
||
const requestWithAgent: Router = RequestWithAgentRouter({ | ||
agent: serverAgent, | ||
}) | ||
|
||
return new Promise((resolve): void => { | ||
const app = express() | ||
app.use(basePath, requestWithAgent, agentRouter) | ||
restServer = app.listen(port, () => { | ||
resolve(true) | ||
}) | ||
}) | ||
} | ||
|
||
const tearDown = async (): Promise<boolean> => { | ||
restServer.close() | ||
return true | ||
} | ||
|
||
const testContext = { | ||
getAgent, | ||
setup, | ||
tearDown, | ||
} | ||
|
||
describe('REST integration tests', () => { | ||
issuanceRestClientAgentLogic(testContext) | ||
}) |
49 changes: 49 additions & 0 deletions
49
packages/oid4vci-issuer-rest-client/__tests__/shared/issuanceRestClientAgentLogic.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,49 @@ | ||
import { TAgent } from '@veramo/core' | ||
import { IOID4VCIRestClient } from '../../src' | ||
|
||
type ConfiguredAgent = TAgent<IOID4VCIRestClient> | ||
|
||
export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Promise<boolean>; tearDown: () => Promise<boolean> }) => { | ||
describe('ssi-sdk.oid4vci-issuer-rest-client', () => { | ||
let agent: ConfiguredAgent | ||
|
||
beforeAll(async () => { | ||
await testContext.setup() | ||
agent = testContext.getAgent() | ||
}) | ||
afterAll(async () => { | ||
await testContext.tearDown() | ||
}) | ||
|
||
it('should create the url Offer Url with baseUrl', async () => { | ||
const result = await agent.vciClientCreateOfferUri({ | ||
baseUrl: 'https://ssi-backend.sphereon.com', | ||
grants: { | ||
'urn:ietf:params:oauth:grant-type:pre-authorized_code': { | ||
'pre-authorized_code': '1234', | ||
user_pin_required: false, | ||
}, | ||
}, | ||
credentials: ['dbc2023'], | ||
}) | ||
expect(result).toEqual({ | ||
uri: 'openid-credential-offer://?credential_offer=%7B%22grants%22%3A%7B%22urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Apre-authorized_code%22%3A%7B%22pre-authorized_code%22%3A%221234%22%2C%22user_pin_required%22%3Afalse%7D%7D%2C%22credentials%22%3A%5B%22dbc2023%22%5D%2C%22credential_issuer%22%3A%22https%3A%2F%2Fdbc2023.test.sphereon.com%2Fissuer%2Fdbc2023%22%7D', | ||
}) | ||
}) | ||
|
||
it('should create the url Offer Url without baseUrl', async () => { | ||
const result = await agent.vciClientCreateOfferUri({ | ||
grants: { | ||
'urn:ietf:params:oauth:grant-type:pre-authorized_code': { | ||
'pre-authorized_code': '1234', | ||
user_pin_required: false, | ||
}, | ||
}, | ||
credentials: ['dbc2023'], | ||
}) | ||
expect(result).toEqual({ | ||
uri: 'openid-credential-offer://?credential_offer=%7B%22grants%22%3A%7B%22urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Apre-authorized_code%22%3A%7B%22pre-authorized_code%22%3A%221234%22%2C%22user_pin_required%22%3Afalse%7D%7D%2C%22credentials%22%3A%5B%22dbc2023%22%5D%2C%22credential_issuer%22%3A%22https%3A%2F%2Fdbc2023.test.sphereon.com%2Fissuer%2Fdbc2023%22%7D', | ||
}) | ||
}) | ||
}) | ||
} |
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,73 @@ | ||
version: 3.0 | ||
|
||
constants: | ||
baseUrl: http://localhost:3335 | ||
port: 3335 | ||
methods: | ||
- vciClientCreateOfferUri | ||
|
||
server: | ||
baseUrl: | ||
$ref: /constants/baseUrl | ||
port: | ||
$ref: /constants/port | ||
use: | ||
# CORS | ||
- - $require: 'cors' | ||
|
||
# Add agent to the request object | ||
- - $require: '@veramo/remote-server?t=function#RequestWithAgentRouter' | ||
$args: | ||
- agent: | ||
$ref: /agent | ||
|
||
# API base path | ||
- - /agent | ||
- $require: '@veramo/remote-server?t=function#apiKeyAuth' | ||
$args: | ||
# Please configure your own API key. This is used when executing agent methods through ${baseUrl}/agent or ${baseUrl}/api-docs | ||
- apiKey: test123 | ||
- $require: '@veramo/remote-server?t=function#AgentRouter' | ||
$args: | ||
- exposedMethods: | ||
$ref: /constants/methods | ||
|
||
# Open API schema | ||
- - /open-api.json | ||
- $require: '@veramo/remote-server?t=function#ApiSchemaRouter' | ||
$args: | ||
- basePath: :3335/agent | ||
securityScheme: bearer | ||
apiName: Agent | ||
apiVersion: '1.0.0' | ||
exposedMethods: | ||
$ref: /constants/methods | ||
|
||
# Swagger docs | ||
- - /api-docs | ||
- $require: swagger-ui-express?t=object#serve | ||
- $require: swagger-ui-express?t=function#setup | ||
$args: | ||
- null | ||
- swaggerOptions: | ||
url: '/open-api.json' | ||
|
||
# Execute during server initialization | ||
init: | ||
- $require: '@veramo/remote-server?t=function#createDefaultDid' | ||
$args: | ||
- agent: | ||
$ref: /agent | ||
baseUrl: | ||
$ref: /constants/baseUrl | ||
messagingServiceEndpoint: /messaging | ||
|
||
# Agent | ||
agent: | ||
$require: '@veramo/core#Agent' | ||
$args: | ||
- schemaValidation: false | ||
plugins: | ||
- $require: ./packages/oid4vci-issuer-rest-client/dist#OID4VCIRestClient | ||
$args: | ||
- baseUrl: 'https://ssi-backend.sphereon.com' |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
packages/oid4vci-rest-client/package.json → ...s/oid4vci-issuer-rest-client/package.json
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
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
File renamed without changes.
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
File renamed without changes.
26 changes: 0 additions & 26 deletions
26
packages/oid4vci-rest-client/__tests__/integration.test.ts
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
packages/oid4vci-rest-client/__tests__/mockedEndpoints.test.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.