Skip to content

Commit 9d57f8d

Browse files
committed
tests passing
1 parent 3191d17 commit 9d57f8d

22 files changed

Lines changed: 4216 additions & 2506 deletions

package-lock.json

Lines changed: 4015 additions & 2332 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
},
3030
"dependencies": {
3131
"@apollo/server": "^4.10.4",
32+
"@aws-sdk/client-s3": "^3.965.0",
3233
"@mikro-orm/better-sqlite": "^6.6.2",
3334
"@mikro-orm/core": "^6.6.2",
3435
"@mikro-orm/migrations": "^6.6.2",
@@ -51,7 +52,6 @@
5152
"@sentry/node": "^7.55.2",
5253
"@sentry/tracing": "^7.55.2",
5354
"adorable-avatars": "^0.5.0",
54-
"aws-sdk": "^2.1397.0",
5555
"bcryptjs": "^2.4.3",
5656
"better-sqlite3": "^12.5.0",
5757
"class-transformer": "^0.5.1",
@@ -71,7 +71,7 @@
7171
"jpeg-js": "^0.4.4",
7272
"lodash": "^4.17.21",
7373
"nestjs-pino": "^3.3.0",
74-
"nestjs-s3": "^1.0.1",
74+
"nestjs-s3": "^3.0.1",
7575
"node-datetime": "^2.1.2",
7676
"nodemailer": "^6.9.3",
7777
"nodemailer-mailgun-transport": "^2.1.5",

src/auth/auth.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { JoinUserHub } from '../dal/entity/joinUserHub.entity';
1212
import { JwtModule } from '@nestjs/jwt';
1313
import { S3Module, S3ModuleOptions } from 'nestjs-s3';
1414
import { ImageFileService } from '../file/image-file/image-file.service';
15-
import { FILE_SERVICE } from '../file/file-service.token';
1615
import { getRepositoryToken } from '@mikro-orm/nestjs';
1716
import { EntityManager, EntityRepository } from '@mikro-orm/core';
1817
import { Block } from '../dal/entity/block.entity';
1918
import { File } from '../dal/entity/file.entity';
2019
import { JoinEventFile } from '../dal/entity/joinEventFile.entity';
2120
import { JoinHubFile } from '../dal/entity/joinHubFile.entity';
21+
import { FileService } from '../file/file-service.abstract';
2222

2323
describe('AuthService', () => {
2424
let service: AuthService;
@@ -55,7 +55,7 @@ describe('AuthService', () => {
5555
UserService,
5656
ImageFileService,
5757
{
58-
provide: FILE_SERVICE,
58+
provide: FileService,
5959
useClass: S3FileService,
6060
},
6161
{

src/event/event.resolver.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Test, TestingModule } from '@nestjs/testing';
55
import { ImageFileService } from '../file/image-file/image-file.service';
66
import { Event } from '../dal/entity/event.entity';
77
import { JoinUserEvent } from '../dal/entity/joinUserEvent.entity';
8-
import { FILE_SERVICE } from '../file/file-service.token';
98
import { LocalFileService } from '../file/local-file/local-file.service';
109
import { EventResolver } from './event.resolver';
1110
import { EventService } from './event.service';
@@ -18,6 +17,7 @@ import { File } from '../dal/entity/file.entity';
1817
import { EventGeofenceService } from './event-geofence/event-geofence.service';
1918
import { JoinEventFile } from '../dal/entity/joinEventFile.entity';
2019
import { EntityManager } from '@mikro-orm/core';
20+
import { FileService } from '../file/file-service.abstract';
2121

2222
describe('EventResolver', () => {
2323
let resolver: EventResolver;
@@ -38,7 +38,7 @@ describe('EventResolver', () => {
3838
ImageFileService,
3939
NotificationService,
4040
{
41-
provide: FILE_SERVICE,
41+
provide: FileService,
4242
useClass: LocalFileService,
4343
},
4444
{

src/event/event.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getRepositoryToken } from '@mikro-orm/nestjs';
22
import { EntityRepository } from '@mikro-orm/postgresql';
33
import { Test, TestingModule } from '@nestjs/testing';
4-
import { FILE_SERVICE } from '../file/file-service.token';
54
import { LocalFileService } from '../file/local-file/local-file.service';
65
import { Event } from '../dal/entity/event.entity';
76
import { JoinUserEvent } from '../dal/entity/joinUserEvent.entity';
@@ -16,6 +15,7 @@ import { UserDevice } from '../dal/entity/userDevice.entity';
1615
import { File } from '../dal/entity/file.entity';
1716
import { JoinEventFile } from '../dal/entity/joinEventFile.entity';
1817
import { EntityManager } from '@mikro-orm/core';
18+
import { FileService } from '../file/file-service.abstract';
1919

2020
describe('EventService', () => {
2121
let service: EventService;
@@ -34,7 +34,7 @@ describe('EventService', () => {
3434
ImageFileService,
3535
NotificationService,
3636
{
37-
provide: FILE_SERVICE,
37+
provide: FileService,
3838
useClass: LocalFileService,
3939
},
4040
{

src/event/event.service.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ import { v4 as uuid } from 'uuid';
66
import { Event } from '../dal/entity/event.entity';
77
import { JoinUserEvent, RSVP } from '../dal/entity/joinUserEvent.entity';
88
import { User } from '../dal/entity/user.entity';
9-
import { FILE_SERVICE } from '../file/file-service.token';
10-
import { FileServiceInterface } from '../file/interfaces/file-service.interface';
119
import { NotificationService } from '../notification/notification.service';
1210
import { JoinEventFile } from '../dal/entity/joinEventFile.entity';
11+
import { FileService } from '../file/file-service.abstract';
1312

1413
@Injectable()
1514
export class EventService {
1615
private readonly logger = new Logger(EventService.name);
1716

1817
constructor(
19-
@Inject(FILE_SERVICE)
20-
private readonly fileService: FileServiceInterface,
18+
@Inject()
19+
private readonly fileService: FileService,
2120
@InjectRepository(JoinUserEvent)
2221
private readonly joinUserEventRepository: EntityRepository<JoinUserEvent>,
2322
@InjectRepository(Event)

src/file/controller/file.controller.spec.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
import { ConfigService } from '@nestjs/config';
22
import { Test, TestingModule } from '@nestjs/testing';
3-
import { FILE_SERVICE } from '../file-service.token';
43
import { FileController } from './file.controller';
54
import { ImageFileService } from '../image-file/image-file.service';
65
import { LocalFileService } from '../local-file/local-file.service';
76
import { getRepositoryToken } from '@mikro-orm/nestjs';
87
import { File } from '../../dal/entity/file.entity';
98
import { EntityManager, EntityRepository } from '@mikro-orm/core';
9+
import { FileService } from '../file-service.abstract';
10+
import fs from 'fs';
11+
12+
jest.mock('fs');
1013

1114
describe('FileController', () => {
1215
let controller: FileController;
1316

1417
beforeEach(async () => {
18+
(fs.existsSync as jest.Mock).mockReturnValue(true);
19+
// eslint-disable-next-line @typescript-eslint/no-empty-function
20+
(fs.mkdirSync as jest.Mock).mockImplementation(() => {});
1521
const module: TestingModule = await Test.createTestingModule({
1622
controllers: [FileController],
1723
providers: [
1824
{
19-
provide: FILE_SERVICE,
25+
provide: FileService,
2026
useClass: LocalFileService,
2127
},
22-
ConfigService,
28+
{
29+
provide: ConfigService,
30+
useValue: {
31+
getOrThrow: jest.fn(() => ''),
32+
},
33+
},
2334
ImageFileService,
2435
{
2536
provide: getRepositoryToken(File),

src/file/controller/file.controller.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { Controller, Get, Header, Inject, Logger, Param, Res } from '@nestjs/common';
22
import { Response } from 'express';
3-
import { join } from 'path';
4-
import sharp from 'sharp';
5-
import { FILE_SERVICE } from '../file-service.token';
63
import { ImageFileService } from '../image-file/image-file.service';
74
import { FileService } from '../file-service.abstract';
85

@@ -11,7 +8,7 @@ export class FileController {
118
private logger = new Logger(FileController.name);
129

1310
constructor(
14-
@Inject(FILE_SERVICE)
11+
@Inject()
1512
private readonly fileService: FileService,
1613
private readonly imageService: ImageFileService,
1714
) {}

src/file/file-service.abstract.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { join } from 'path';
55
import sharp from 'sharp';
66
import { File } from 'src/dal/entity/file.entity';
77
import Stream, { Readable } from 'stream';
8-
import { Observable } from 'rxjs';
9-
import { MultipartFileStream } from '@proventuslabs/nestjs-multipart-form';
108
import { FileServiceInterface } from './interfaces/file-service.interface';
9+
import { FileUpload } from './interfaces/file-upload.interface';
10+
import { ReadStream } from 'fs';
11+
1112

1213
@Injectable()
1314
export abstract class FileService implements FileServiceInterface {
@@ -18,13 +19,13 @@ export abstract class FileService implements FileServiceInterface {
1819
constructor(readonly configService: ConfigService) {}
1920

2021
abstract storeImageFromFileUpload(
21-
upload$: Observable<MultipartFileStream>,
22+
upload: Promise<FileUpload> | FileUpload,
2223
userId: any,
2324
): Promise<File>;
2425
abstract delete(fileName: string): Promise<void>;
2526
abstract deleteById(fileId: any, userId: any): Promise<any>;
26-
abstract get(fileName: string): Promise<Readable | undefined>;
27-
abstract getByShareableId(shareableId: string): Promise<Readable | undefined>;
27+
abstract get(fileName: string): Promise<Readable>;
28+
abstract getByShareableId(shareableId: string): Promise<Readable>;
2829

2930
async getWatermark() {
3031
return sharp(

src/file/file.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { FactoryProvider, Logger, Module } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
3-
import { FILE_SERVICE } from './file-service.token';
43
import { FileController } from './controller/file.controller';
54
import { ImageFileService } from './image-file/image-file.service';
65
import { LocalFileService } from './local-file/local-file.service';
@@ -10,9 +9,10 @@ import * as path from 'path';
109
import { MikroOrmModule } from '@mikro-orm/nestjs';
1110
import { File } from '../dal/entity/file.entity';
1211
import { FileResolver } from './resolver/file.resolver';
12+
import { FileService } from './file-service.abstract';
1313

1414
export const fileServiceFactory = {
15-
provide: FILE_SERVICE,
15+
provide: FileService,
1616
useFactory: (
1717
configService: ConfigService,
1818
localFileService: LocalFileService,
@@ -56,7 +56,7 @@ export const fileServiceFactory = {
5656
FileUrlService,
5757
FileResolver,
5858
],
59-
exports: [FILE_SERVICE, FileUrlService],
59+
exports: [FileService, FileUrlService],
6060
})
6161
export class FileModule {
6262
public static logger = new Logger(FileModule.name);

0 commit comments

Comments
 (0)