Skip to content

Commit

Permalink
test: update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Jan 15, 2024
1 parent 8cf88e8 commit b6c281e
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions apps/auth/src/app/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { Test, TestingModule } from '@nestjs/testing';

import { AppController } from './app.controller';
Expand Down
1 change: 1 addition & 0 deletions apps/auth/src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { Test } from '@nestjs/testing';

import { AppService } from './app.service';
Expand Down
1 change: 1 addition & 0 deletions apps/expiration/src/app/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { Test, TestingModule } from '@nestjs/testing';

import { AppController } from './app.controller';
Expand Down
1 change: 1 addition & 0 deletions apps/expiration/src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { Test } from '@nestjs/testing';

import { AppService } from './app.service';
Expand Down
1 change: 1 addition & 0 deletions apps/orders/src/app/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { Test, TestingModule } from '@nestjs/testing';

import { AppController } from './app.controller';
Expand Down
1 change: 1 addition & 0 deletions apps/orders/src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { Test } from '@nestjs/testing';

import { AppService } from './app.service';
Expand Down
10 changes: 8 additions & 2 deletions apps/orders/src/app/orders/orders-ms.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* eslint-disable max-nested-callbacks */
/* eslint-disable max-lines-per-function */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { OryPermissionsService } from '@getlarge/keto-client-wrapper';
import { jest } from '@jest/globals';
import { ConfigService } from '@nestjs/config';
import { Test, TestingModule } from '@nestjs/testing';
import {
createRmqContext,
MockModel,
MockOryPermissionService,
MockOryPermissionsService,
MockOryRelationshipsService,
MockPublisher,
} from '@ticketing/microservices/shared/testing';
import { Channel } from 'amqp-connection-manager';
Expand All @@ -30,12 +32,16 @@ describe('OrdersMSController', () => {
new MockModel() as any,
new MockModel() as any,
new ConfigService({ EXPIRATION_WINDOW_SECONDS: 15 * 60 }),
new MockOryPermissionService() as any,
new MockOryRelationshipsService() as any,
new MockPublisher() as any,
new MockPublisher() as any,
new MockPublisher() as any,
),
},
{
provide: OryPermissionsService,
useValue: new MockOryPermissionsService() as any,
},
],
}).compile();
});
Expand Down
1 change: 1 addition & 0 deletions apps/payments/src/app/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { Test, TestingModule } from '@nestjs/testing';

import { AppController } from './app.controller';
Expand Down
1 change: 1 addition & 0 deletions apps/payments/src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { Test } from '@nestjs/testing';

import { AppService } from './app.service';
Expand Down
23 changes: 14 additions & 9 deletions apps/permissions-manager/src/app/create-relation.command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import {
OryRelationshipsModule,
OryRelationshipsService,
} from '@getlarge/keto-client-wrapper';
import { RelationTuple } from '@getlarge/keto-relations-parser';
import {
createRelationQuery,
RelationTuple,
} from '@getlarge/keto-relations-parser';
import { jest } from '@jest/globals';
import { MockOryPermissionService } from '@ticketing/microservices/shared/testing';
import { MockOryRelationshipsService } from '@ticketing/microservices/shared/testing';
import { CommandTestFactory } from 'nest-commander-testing';

import { CreateRelationCommand } from './create-relation.command';

describe('CreateRelationCommand', () => {
let service: CreateRelationCommand;
const mockOryRelationshipsService = new MockOryRelationshipsService();

beforeAll(async () => {
const app = await CommandTestFactory.createTestingCommand({
Expand All @@ -25,15 +29,15 @@ describe('CreateRelationCommand', () => {
providers: [CreateRelationCommand],
})
.overrideProvider(OryRelationshipsService)
.useClass(MockOryPermissionService)
.useValue(mockOryRelationshipsService)
.compile();

service = app.get<CreateRelationCommand>(CreateRelationCommand);
});

describe('run', () => {
it('should process tuple and create relationship', async () => {
const expectedTuple: RelationTuple = {
const tuple: RelationTuple = {
namespace: 'Group',
object: 'admin',
relation: 'members',
Expand All @@ -42,18 +46,19 @@ describe('CreateRelationCommand', () => {
object: '1',
},
};
service['oryPermissionsService'].createRelation = jest
const expectedQuery = createRelationQuery(tuple).unwrapOrThrow();
mockOryRelationshipsService.createRelationship = jest
.fn(() => Promise.resolve(true))
.mockResolvedValue(true);

await expect(
service.run(['--tuple', 'Group:admin#members@User:1'], {
tuple: expectedTuple,
tuple: expectedQuery,
}),
).resolves.toBeUndefined();
expect(service['oryPermissionsService'].createRelation).toBeCalledWith(
expectedTuple,
);
expect(mockOryRelationshipsService.createRelationship).toBeCalledWith({
createRelationshipBody: expectedQuery,
});
});
});
});
1 change: 1 addition & 0 deletions apps/tickets/src/app/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { Test, TestingModule } from '@nestjs/testing';

import { AppController } from './app.controller';
Expand Down
1 change: 1 addition & 0 deletions apps/tickets/src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals';
import { Test } from '@nestjs/testing';

import { AppService } from './app.service';
Expand Down
4 changes: 2 additions & 2 deletions apps/tickets/src/app/orders/orders-ms.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import {
createRmqContext,
MockModel,
MockOryPermissionService,
MockOryRelationshipsService,
MockPublisher,
} from '@ticketing/microservices/shared/testing';
import { Channel } from 'amqp-connection-manager';
Expand All @@ -27,7 +27,7 @@ describe('OrdersMSController', () => {
provide: TicketsService,
useValue: new TicketsService(
new MockModel() as any,
new MockOryPermissionService() as any,
new MockOryRelationshipsService() as any,
new MockPublisher() as any,
),
},
Expand Down

0 comments on commit b6c281e

Please sign in to comment.