Skip to content

Commit

Permalink
Merge branch 'main' into N21-2096-force-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap authored Jul 24, 2024
2 parents dfd22a4 + b54cc3c commit a66a0a6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 71 deletions.
18 changes: 12 additions & 6 deletions apps/server/src/infra/preview-generator/preview.producer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { PreviewProducer } from './preview.producer';
describe('PreviewProducer', () => {
let module: TestingModule;
let service: PreviewProducer;
let configService: DeepMocked<ConfigService>;
let amqpConnection: DeepMocked<AmqpConnection>;

const timeout = 10000;

beforeAll(async () => {
await setupEntities();
module = await Test.createTestingModule({
Expand All @@ -30,14 +31,20 @@ describe('PreviewProducer', () => {
},
{
provide: ConfigService,
useValue: createMock<ConfigService>(),
useValue: createMock<ConfigService>({
get: jest.fn().mockImplementation((key: string) => {
if (key === 'INCOMING_REQUEST_TIMEOUT') {
return timeout;
}
throw new Error('Config key not found');
}),
}),
},
],
}).compile();

service = module.get(PreviewProducer);
amqpConnection = module.get(AmqpConnection);
configService = module.get(ConfigService);
});

afterAll(async () => {
Expand All @@ -47,15 +54,14 @@ describe('PreviewProducer', () => {
afterEach(() => {
jest.resetAllMocks();
});

it('should be defined', () => {
expect(service).toBeDefined();
});

describe('generate', () => {
describe('when valid params are passed and amqp connection return with a message', () => {
const setup = () => {
const timeout = 10000;

const params: PreviewFileOptions = {
originFilePath: 'file/test.jpeg',
previewFilePath: 'preview/text.webp',
Expand All @@ -67,13 +73,13 @@ describe('PreviewProducer', () => {

const message = [];
amqpConnection.request.mockResolvedValueOnce({ message });
configService.get.mockReturnValue(timeout);

const expectedParams = {
exchange: FilesPreviewExchange,
routingKey: FilesPreviewEvents.GENERATE_PREVIEW,
payload: params,
timeout,
expiration: timeout * 1.5,
};

return { params, expectedParams, message };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('RpcMessageProducer', () => {
routingKey: TestEvent,
payload: params,
timeout,
expiration: timeout * 1.5,
};

return { params, expectedParams, message };
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/infra/rabbitmq/rpc-message-producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ export abstract class RpcMessageProducer {
}

protected createRequest(event: string, payload: unknown) {
// expiration should be greater than timeout
const expiration = this.timeout > 0 ? this.timeout * 1.5 : undefined;

return {
exchange: this.exchange,
routingKey: event,
payload,
timeout: this.timeout,
expiration,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { FilesStorageProducer } from './files-storage.producer';
describe('FilesStorageProducer', () => {
let module: TestingModule;
let service: FilesStorageProducer;
let configService: DeepMocked<ConfigService>;
let amqpConnection: DeepMocked<AmqpConnection>;

const timeout = 10000;
Expand All @@ -32,21 +31,30 @@ describe('FilesStorageProducer', () => {
},
{
provide: ConfigService,
useValue: createMock<ConfigService>(),
useValue: createMock<ConfigService>({
get: jest.fn().mockImplementation((key: string) => {
if (key === 'INCOMING_REQUEST_TIMEOUT_COPY_API') {
return timeout;
}
throw new Error('Config key not found');
}),
}),
},
],
}).compile();

service = module.get(FilesStorageProducer);
amqpConnection = module.get(AmqpConnection);
configService = module.get(ConfigService);
configService.get.mockReturnValue(timeout);
});

afterAll(async () => {
await module.close();
});

afterEach(() => {
jest.clearAllMocks();
});

describe('copyFilesOfParent', () => {
describe('when amqpConnection return with error in response', () => {
const setup = () => {
Expand Down Expand Up @@ -111,6 +119,7 @@ describe('FilesStorageProducer', () => {
routingKey: FilesStorageEvents.COPY_FILES_OF_PARENT,
payload: params,
timeout,
expiration: timeout * 1.5,
};

return { params, expectedParams, message };
Expand Down Expand Up @@ -163,6 +172,7 @@ describe('FilesStorageProducer', () => {
routingKey: FilesStorageEvents.LIST_FILES_OF_PARENT,
payload: parentId,
timeout,
expiration: timeout * 1.5,
};

const message = [];
Expand Down Expand Up @@ -221,6 +231,7 @@ describe('FilesStorageProducer', () => {
routingKey: FilesStorageEvents.DELETE_FILES_OF_PARENT,
payload: parentId,
timeout,
expiration: timeout * 1.5,
};

return { parentId, message, expectedParams };
Expand Down Expand Up @@ -275,6 +286,7 @@ describe('FilesStorageProducer', () => {
routingKey: FilesStorageEvents.DELETE_FILES,
payload: [recordId],
timeout,
expiration: timeout * 1.5,
};
return { recordId, message, expectedParams };
};
Expand Down Expand Up @@ -329,6 +341,7 @@ describe('FilesStorageProducer', () => {
routingKey: FilesStorageEvents.REMOVE_CREATORID_OF_FILES,
payload: creatorId,
timeout,
expiration: timeout * 1.5,
};

return { creatorId, message, expectedParams };
Expand Down
101 changes: 42 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
"ioredis": "^5.3.2",
"jose": "^5.6.3",
"jsdom": "^23.2.0",
"jsonwebtoken": "^9.0.0",
"jsonwebtoken": "^9.0.2",
"jwks-rsa": "^2.0.5",
"ldapjs": "git://github.com/hpi-schul-cloud/node-ldapjs.git",
"lodash": "^4.17.19",
Expand Down Expand Up @@ -320,7 +320,7 @@
"mocha": "^9.1.3",
"mockery": "^2.0.0",
"nock": "^13.0.0",
"nodemon": "^2.0.2",
"nodemon": "^3.1.4",
"nyc": "^15.0.1",
"prettier": "^2.8.1",
"prettier-eslint": "^12.0.0",
Expand Down

0 comments on commit a66a0a6

Please sign in to comment.