Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Jul 5, 2022
1 parent df1ea46 commit 167e67a
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ describe('RevocationNotificationService', () => {

expect(eventListenerMock).toHaveBeenCalledWith({
type: 'RevocationNotificationReceived',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
credentialRecord: expect.any(CredentialExchangeRecord),
},
Expand Down Expand Up @@ -208,6 +211,9 @@ describe('RevocationNotificationService', () => {

expect(eventListenerMock).toHaveBeenCalledWith({
type: 'RevocationNotificationReceived',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
credentialRecord: expect.any(CredentialExchangeRecord),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ describe('V1CredentialService', () => {
// then
expect(eventListenerMock).toHaveBeenCalledWith({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: CredentialState.RequestReceived,
credentialRecord: expect.objectContaining({
Expand Down Expand Up @@ -608,6 +611,9 @@ describe('V1CredentialService', () => {
// then
expect(eventListenerMock).toHaveBeenCalledWith({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: CredentialState.CredentialReceived,
credentialRecord: expect.objectContaining({
Expand Down Expand Up @@ -934,6 +940,9 @@ describe('V1CredentialService', () => {
const [[event]] = eventListenerMock.mock.calls
expect(event).toMatchObject({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: CredentialState.OfferReceived,
credentialRecord: expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ describe('V1CredentialServiceProposeOffer', () => {

expect(eventListenerMock).toHaveBeenCalledWith({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: null,
credentialRecord: expect.objectContaining({
Expand Down Expand Up @@ -289,6 +292,9 @@ describe('V1CredentialServiceProposeOffer', () => {

expect(eventListenerMock).toHaveBeenCalledWith({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: null,
credentialRecord: expect.objectContaining({
Expand Down Expand Up @@ -385,6 +391,9 @@ describe('V1CredentialServiceProposeOffer', () => {
// then
expect(eventListenerMock).toHaveBeenCalledWith({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: null,
credentialRecord: expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ describe('CredentialService', () => {
// then
expect(eventListenerMock).toHaveBeenCalledWith({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: CredentialState.RequestReceived,
credentialRecord: expect.objectContaining({
Expand Down Expand Up @@ -590,6 +593,9 @@ describe('CredentialService', () => {
// then
expect(eventListenerMock).toHaveBeenCalledWith({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: CredentialState.CredentialReceived,
credentialRecord: expect.objectContaining({
Expand Down Expand Up @@ -887,6 +893,9 @@ describe('CredentialService', () => {
const [[event]] = eventListenerMock.mock.calls
expect(event).toMatchObject({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: CredentialState.OfferReceived,
credentialRecord: expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ describe('V2CredentialServiceOffer', () => {

expect(eventListenerMock).toHaveBeenCalledWith({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: null,
credentialRecord: expect.objectContaining({
Expand Down Expand Up @@ -248,6 +251,9 @@ describe('V2CredentialServiceOffer', () => {
// then
expect(eventListenerMock).toHaveBeenCalledWith({
type: 'CredentialStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: null,
credentialRecord: expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ describe('ProofService', () => {
// then
expect(eventListenerMock).toHaveBeenCalledWith({
type: 'ProofStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: null,
proofRecord: expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ describe('QuestionAnswerService', () => {

expect(eventListenerMock).toHaveBeenCalledWith({
type: 'QuestionAnswerStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: null,
questionAnswerRecord: expect.objectContaining({
Expand Down Expand Up @@ -146,6 +149,9 @@ describe('QuestionAnswerService', () => {

expect(eventListenerMock).toHaveBeenCalledWith({
type: 'QuestionAnswerStateChanged',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
previousState: QuestionAnswerState.QuestionReceived,
questionAnswerRecord: expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ describe('RoutingService', () => {
expect(routing).toEqual(routing)
expect(routingListener).toHaveBeenCalledWith({
type: RoutingEventTypes.RoutingCreatedEvent,
metadata: {
contextCorrelationId: 'mock',
},
payload: {
routing,
},
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/storage/__tests__/Repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ describe('Repository', () => {
// then
expect(eventListenerMock).toHaveBeenCalledWith({
type: 'RecordSaved',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
record: expect.objectContaining({
id: 'test-id',
Expand Down Expand Up @@ -91,6 +94,9 @@ describe('Repository', () => {
// then
expect(eventListenerMock).toHaveBeenCalledWith({
type: 'RecordUpdated',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
record: expect.objectContaining({
id: 'test-id',
Expand Down Expand Up @@ -121,6 +127,9 @@ describe('Repository', () => {
// then
expect(eventListenerMock).toHaveBeenCalledWith({
type: 'RecordDeleted',
metadata: {
contextCorrelationId: 'mock',
},
payload: {
record: expect.objectContaining({
id: 'test-id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('UpdateAssistant', () => {

beforeEach(async () => {
const dependencyManager = new DependencyManager()
const storageService = new InMemoryStorageService()
storageService = new InMemoryStorageService()
dependencyManager.registerInstance(InjectionSymbols.StorageService, storageService)

agent = new Agent(config, agentDependencies, dependencyManager)
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/utils/JWE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import type { EncryptedMessage } from '../types'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isValidJweStructure(message: any): message is EncryptedMessage {
return (
return Boolean(
message &&
typeof message === 'object' &&
message !== null &&
typeof message.protected === 'string' &&
message.iv &&
message.ciphertext &&
message.tag
typeof message === 'object' &&
message !== null &&
typeof message.protected === 'string' &&
message.iv &&
message.ciphertext &&
message.tag
)
}
9 changes: 9 additions & 0 deletions packages/core/tests/oob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ describe('out of band', () => {

expect(eventListener).toHaveBeenCalledWith({
type: OutOfBandEventTypes.OutOfBandStateChanged,
metadata: {
contextCorrelationId: 'default',
},
payload: {
outOfBandRecord,
previousState: null,
Expand Down Expand Up @@ -583,6 +586,9 @@ describe('out of band', () => {
// Receiving the invitation
expect(eventListener).toHaveBeenNthCalledWith(1, {
type: OutOfBandEventTypes.OutOfBandStateChanged,
metadata: {
contextCorrelationId: 'default',
},
payload: {
outOfBandRecord: expect.objectContaining({ state: OutOfBandState.Initial }),
previousState: null,
Expand All @@ -592,6 +598,9 @@ describe('out of band', () => {
// Accepting the invitation
expect(eventListener).toHaveBeenNthCalledWith(2, {
type: OutOfBandEventTypes.OutOfBandStateChanged,
metadata: {
contextCorrelationId: 'default',
},
payload: {
outOfBandRecord,
previousState: OutOfBandState.Initial,
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions packages/module-tenants/src/__tests__/TenantsModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ describe('TenantsModule', () => {
test('registers dependencies on the dependency manager', () => {
TenantsModule.register(dependencyManager)

expect(dependencyManager.registerContextScoped).toHaveBeenCalledTimes(1)
expect(dependencyManager.registerContextScoped).toHaveBeenCalledWith(TenantsApi)

expect(dependencyManager.registerSingleton).toHaveBeenCalledTimes(5)
expect(dependencyManager.registerSingleton).toHaveBeenCalledTimes(6)
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(TenantsApi)
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(TenantService)
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(TenantRepository)
expect(dependencyManager.registerSingleton).toHaveBeenCalledWith(TenantRoutingRepository)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { TenantRepository } from '../../repository/TenantRepository'
import { TenantRoutingRepository } from '../../repository/TenantRoutingRepository'
import { TenantService } from '../TenantService'

jest.mock('../repository/TenantRepository')
jest.mock('../../repository/TenantRepository')
const TenantRepositoryMock = TenantRepository as jest.Mock<TenantRepository>
jest.mock('../repository/TenantRoutingRepository')
jest.mock('../../repository/TenantRoutingRepository')
const TenantRoutingRepositoryMock = TenantRoutingRepository as jest.Mock<TenantRoutingRepository>

const wallet = {
Expand Down

0 comments on commit 167e67a

Please sign in to comment.