Skip to content

Commit

Permalink
test: creates mocked tests for post manager to prove out functionality (
Browse files Browse the repository at this point in the history
#325)

* test: creates fullblown mock tests for major post manager features
  • Loading branch information
mvdicarlo authored Jan 6, 2025
1 parent 9ff7d80 commit b27668c
Show file tree
Hide file tree
Showing 25 changed files with 678 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
IPostRecordMetadata,
IWebsiteError,
IWebsitePostRecord,
PostData,
WebsitePostRecordDto,
} from '@postybirb/types';
import { PostyBirbRepository } from '../repositories/postybirb-repository';
Expand Down Expand Up @@ -55,6 +56,9 @@ export class WebsitePostRecord
@Property({ type: 'json', nullable: true })
errors?: IWebsiteError[];

@Property({ type: 'json', nullable: true })
postData?: PostData;

toJSON(): WebsitePostRecordDto {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return serialize(this as any, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class PostParsersService {
submission: ISubmission,
instance: UnknownWebsite,
websiteOptions: IWebsiteOptions,
): Promise<PostData<ISubmission, IWebsiteFormFields>> {
): Promise<PostData<IWebsiteFormFields>> {
const defaultOptions: IWebsiteOptions = submission.options.find(
(o) => o.isDefault,
);
Expand Down
9 changes: 8 additions & 1 deletion apps/client-server/src/app/post/models/posting-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
FileMetadataFields,
FileType,
IFileBuffer,
IFileDimensions,
SubmissionFileId,
} from '@postybirb/types';
import { getFileType } from '@postybirb/utils/file-type';
Expand All @@ -10,7 +11,7 @@ import { parse } from 'path';
export type ThumbnailOptions = {
buffer: Buffer;
fileName: string;
};
} & Omit<IFileDimensions, 'size'>;

export class PostingFile {
public readonly id: SubmissionFileId;
Expand All @@ -23,6 +24,10 @@ export class PostingFile {

public readonly fileName: string;

public readonly width: number;

public readonly height: number;

public metadata: FileMetadataFields;

public readonly thumbnail?: ThumbnailOptions;
Expand All @@ -35,6 +40,8 @@ export class PostingFile {
this.id = id;
this.buffer = file.buffer;
this.mimeType = file.mimeType;
this.width = file.width;
this.height = file.height;
this.fileType = getFileType(file.fileName);
this.fileName = this.normalizeFileName(file);
this.thumbnail = thumbnail;
Expand Down
114 changes: 0 additions & 114 deletions apps/client-server/src/app/post/post.service.spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ describe('PostFileResizerService', () => {
}

beforeAll(() => {
testFile = readFileSync(join(__dirname, '../test-files/small_image.jpg'));
testFile = readFileSync(
join(__dirname, '../../../test-files/small_image.jpg'),
);
file = createFile('test.jpg', 'image/jpeg', 202, 138, testFile);
});

Expand Down Expand Up @@ -125,7 +127,7 @@ describe('PostFileResizerService', () => {

it('should convert png thumbnail without alpha to jpeg', async () => {
const noAlphaFile = readFileSync(
join(__dirname, '../test-files/png_no_alpha.png'),
join(__dirname, '../../../test-files/png_no_alpha.png'),
);
const tf = createFile('test.png', 'image/png', 600, 600, noAlphaFile);
const resized = await service.resize({
Expand All @@ -141,7 +143,7 @@ describe('PostFileResizerService', () => {

it('should not convert png thumbnail with alpha to jpeg', async () => {
const noAlphaFile = readFileSync(
join(__dirname, '../test-files/png_with_alpha.png'),
join(__dirname, '../../../test-files/png_with_alpha.png'),
);
const tf = createFile('test.png', 'image/png', 600, 600, noAlphaFile);
const resized = await service.resize({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export class PostFileResizerService {
fileName: `${file.id}.${m.format}`,
buffer: await sharpInstance.toBuffer(),
mimeType: `image/${m.format}`,
height: m.height,
width: m.width,
};
}

Expand Down Expand Up @@ -137,6 +139,8 @@ export class PostFileResizerService {
return {
buffer: await instance.toBuffer(),
fileName: `${name}${extension}`,
width: metadata.width,
height: metadata.height,
};
}

Expand Down
Loading

0 comments on commit b27668c

Please sign in to comment.