universo-platform-3d
120 строк · 4.1 Кб
1import { INestApplication, forwardRef } from '@nestjs/common'
2import { Test, TestingModule } from '@nestjs/testing'
3import request from 'supertest'
4import { beforeAll, describe, it, vi } from 'vitest'
5import { AssetController } from '../src/asset/asset.controller'
6import { AssetService } from '../src/asset/asset.service'
7import { FirebaseAuthenticationService } from '../src/firebase/firebase-authentication.service'
8import { RoleService } from '../src/roles/role.service'
9import { FileUploadService } from '../src/util/file-upload/file-upload.service'
10import { LoggerModule } from '../src/util/logger/logger.module'
11import { PaginationService } from '../src/util/pagination/pagination.service'
12import { AssetSearch } from './../src/asset/asset.search'
13import {
14getMockClassesForProvidersArray,
15getMockMongooseModelsForProvidersArray
16} from './mocks/service.mocks'
17import { UserService } from '../src/user/user.service'
18import { UserModule } from '../src/user/user.module'
19import { AssetAnalyzingService } from '../src/util/file-analyzing/asset-analyzing.service'
20import { AuthGuardFirebase } from '../src/auth/auth.guard'
21import { StorageService } from '../src/storage/storage.service'
22import { StripeService } from '../src/stripe/stripe.service'
23
24describe('Asset Controller (Integration)', () => {
25let app: INestApplication
26let assetService: AssetService
27
28beforeAll(async () => {
29const moduleFixture: TestingModule = await Test.createTestingModule({
30imports: [LoggerModule],
31controllers: [AssetController],
32providers: [
33...getMockClassesForProvidersArray([
34FileUploadService,
35FirebaseAuthenticationService
36]),
37AssetService,
38AssetSearch,
39PaginationService,
40RoleService,
41{ provide: UserService, useValue: {} },
42...getMockMongooseModelsForProvidersArray(),
43{ provide: AssetAnalyzingService, useValue: {} },
44{ provide: AuthGuardFirebase, useValue: {} },
45{ provide: StorageService, useValue: {} },
46{ provide: StripeService, useValue: {} }
47]
48})
49.overrideProvider(FileUploadService)
50.useValue({})
51.compile()
52
53app = moduleFixture.createNestApplication()
54await app.init()
55
56assetService = moduleFixture.get(AssetService)
57})
58
59describe('Publicly accessible endpoints', () => {
60it('should pass search without firebase auth', () => {
61vi.spyOn(assetService, 'searchAssetsPublic').mockImplementation(
62async () => []
63)
64
65return request(app.getHttpServer())
66.get('/asset/search?email=test@test.com')
67.expect(200)
68})
69})
70
71describe('Auth required endpoints', () => {
72it('should fail getMirrorPublicLibraryAssets without firebase auth', () => {
73return request(app.getHttpServer()).get('/asset/library').expect(403)
74})
75
76it('should fail create without firebase auth', () => {
77return request(app.getHttpServer()).post('/asset').expect(403)
78})
79
80it('should fail getAssetsForMe without firebase auth', () => {
81return request(app.getHttpServer()).get('/asset/me').expect(403)
82})
83
84it('should fail findAllForUser without firebase auth', () => {
85return request(app.getHttpServer())
86.get('/asset/user/test-asset-id')
87.expect(403)
88})
89
90it('should fail findOne without firebase auth', () => {
91return request(app.getHttpServer())
92.get('/asset/test-asset-id')
93.expect(403)
94})
95
96it('should fail update without firebase auth', () => {
97return request(app.getHttpServer())
98.patch('/asset/test-asset-id')
99.expect(403)
100})
101
102it('should fail remove without firebase auth', () => {
103return request(app.getHttpServer())
104.delete('/asset/test-asset-id')
105.expect(403)
106})
107
108it('should fail upload without firebase auth', () => {
109return request(app.getHttpServer())
110.post('/asset/test-asset-id/upload')
111.expect(403)
112})
113
114it('should fail uploadPublic without firebase auth', () => {
115return request(app.getHttpServer())
116.post('/asset/test-asset-id/upload/public')
117.expect(403)
118})
119})
120})
121