Skip to content

Commit

Permalink
N21-1319 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrikallab committed Nov 17, 2023
1 parent 338b9ff commit f25c3fb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ObjectId } from '@mikro-orm/mongodb';
import { Test, TestingModule } from '@nestjs/testing';
import { ContextExternalToolRepo, ExternalToolRepo, SchoolExternalToolRepo } from '@shared/repo';
import { ContextExternalToolRepo, SchoolExternalToolRepo } from '@shared/repo';
import { externalToolFactory, legacySchoolDoFactory, schoolExternalToolFactory } from '@shared/testing';
import { ContextExternalToolType } from '../../context-external-tool/entity';
import { SchoolExternalTool } from '../../school-external-tool/domain';
Expand All @@ -12,18 +12,13 @@ describe('ExternalToolMetadataService', () => {
let module: TestingModule;
let service: ExternalToolMetadataService;

let externalToolRepo: DeepMocked<ExternalToolRepo>;
let schoolExternalToolRepo: DeepMocked<SchoolExternalToolRepo>;
let contextExternalToolRepo: DeepMocked<ContextExternalToolRepo>;

beforeAll(async () => {
module = await Test.createTestingModule({
providers: [
ExternalToolMetadataService,
{
provide: ExternalToolRepo,
useValue: createMock<ExternalToolRepo>(),
},
{
provide: SchoolExternalToolRepo,
useValue: createMock<SchoolExternalToolRepo>(),
Expand All @@ -36,7 +31,6 @@ describe('ExternalToolMetadataService', () => {
}).compile();

service = module.get(ExternalToolMetadataService);
externalToolRepo = module.get(ExternalToolRepo);
schoolExternalToolRepo = module.get(SchoolExternalToolRepo);
contextExternalToolRepo = module.get(ContextExternalToolRepo);
});
Expand All @@ -53,7 +47,6 @@ describe('ExternalToolMetadataService', () => {
describe('when externalToolId is given', () => {
const setup = () => {
const toolId: string = new ObjectId().toHexString();
const externalTool: ExternalTool = externalToolFactory.buildWithId(undefined, toolId);

const school = legacySchoolDoFactory.buildWithId();
const school1 = legacySchoolDoFactory.buildWithId();
Expand All @@ -76,7 +69,6 @@ describe('ExternalToolMetadataService', () => {
contextExternalToolCountPerContext: { course: 3, boardElement: 3 },
});

externalToolRepo.findById.mockResolvedValue(externalTool);
schoolExternalToolRepo.findByExternalToolId.mockResolvedValue([schoolExternalTool, schoolExternalTool1]);
contextExternalToolRepo.countBySchoolToolIdsAndContextType.mockResolvedValue(3);

Expand Down Expand Up @@ -131,7 +123,6 @@ describe('ExternalToolMetadataService', () => {
contextExternalToolCountPerContext: { course: 0, boardElement: 0 },
});

externalToolRepo.findById.mockResolvedValue(externalToolEntity);
schoolExternalToolRepo.findByExternalToolId.mockResolvedValue([]);
contextExternalToolRepo.countBySchoolToolIdsAndContextType.mockResolvedValue(0);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { EntityId } from '@shared/domain';
import { ContextExternalToolRepo, ExternalToolRepo, SchoolExternalToolRepo } from '@shared/repo';
import { ContextExternalToolRepo, SchoolExternalToolRepo } from '@shared/repo';
import { ToolContextType } from '../../common/enum';
import { ContextExternalToolType } from '../../context-external-tool/entity';
import { SchoolExternalTool } from '../../school-external-tool/domain';
Expand All @@ -10,7 +10,6 @@ import { ToolContextMapper } from '../../common/mapper/tool-context.mapper';
@Injectable()
export class ExternalToolMetadataService {
constructor(
private readonly externalToolRepo: ExternalToolRepo,
private readonly schoolToolRepo: SchoolExternalToolRepo,
private readonly contextToolRepo: ContextExternalToolRepo
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ export class SchoolExternalToolMetadataService {
[ContextExternalToolType.COURSE]: 0,
};

if (schoolExternalToolId) {
await Promise.all(
Object.values(ToolContextType).map(async (contextType: ToolContextType): Promise<void> => {
const type: ContextExternalToolType = ToolContextMapper.contextMapping[contextType];
await Promise.all(
Object.values(ToolContextType).map(async (contextType: ToolContextType): Promise<void> => {
const type: ContextExternalToolType = ToolContextMapper.contextMapping[contextType];

const countPerContext: number = await this.contextToolRepo.countBySchoolToolIdsAndContextType(type, [
schoolExternalToolId,
]);
contextExternalToolCount[type] = countPerContext;
})
);
}
const countPerContext: number = await this.contextToolRepo.countBySchoolToolIdsAndContextType(type, [
schoolExternalToolId,
]);

contextExternalToolCount[type] = countPerContext;
})
);

const schoolExternaltoolMetadata: SchoolExternalToolMetadata = new SchoolExternalToolMetadata({
contextExternalToolCountPerContext: contextExternalToolCount,
Expand Down

0 comments on commit f25c3fb

Please sign in to comment.