universo-platform-3d

Форк
0
/
asset.integration-spec.ts 
120 строк · 4.1 Кб
1
import { INestApplication, forwardRef } from '@nestjs/common'
2
import { Test, TestingModule } from '@nestjs/testing'
3
import request from 'supertest'
4
import { beforeAll, describe, it, vi } from 'vitest'
5
import { AssetController } from '../src/asset/asset.controller'
6
import { AssetService } from '../src/asset/asset.service'
7
import { FirebaseAuthenticationService } from '../src/firebase/firebase-authentication.service'
8
import { RoleService } from '../src/roles/role.service'
9
import { FileUploadService } from '../src/util/file-upload/file-upload.service'
10
import { LoggerModule } from '../src/util/logger/logger.module'
11
import { PaginationService } from '../src/util/pagination/pagination.service'
12
import { AssetSearch } from './../src/asset/asset.search'
13
import {
14
  getMockClassesForProvidersArray,
15
  getMockMongooseModelsForProvidersArray
16
} from './mocks/service.mocks'
17
import { UserService } from '../src/user/user.service'
18
import { UserModule } from '../src/user/user.module'
19
import { AssetAnalyzingService } from '../src/util/file-analyzing/asset-analyzing.service'
20
import { AuthGuardFirebase } from '../src/auth/auth.guard'
21
import { StorageService } from '../src/storage/storage.service'
22
import { StripeService } from '../src/stripe/stripe.service'
23

24
describe('Asset Controller (Integration)', () => {
25
  let app: INestApplication
26
  let assetService: AssetService
27

28
  beforeAll(async () => {
29
    const moduleFixture: TestingModule = await Test.createTestingModule({
30
      imports: [LoggerModule],
31
      controllers: [AssetController],
32
      providers: [
33
        ...getMockClassesForProvidersArray([
34
          FileUploadService,
35
          FirebaseAuthenticationService
36
        ]),
37
        AssetService,
38
        AssetSearch,
39
        PaginationService,
40
        RoleService,
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

53
    app = moduleFixture.createNestApplication()
54
    await app.init()
55

56
    assetService = moduleFixture.get(AssetService)
57
  })
58

59
  describe('Publicly accessible endpoints', () => {
60
    it('should pass search without firebase auth', () => {
61
      vi.spyOn(assetService, 'searchAssetsPublic').mockImplementation(
62
        async () => []
63
      )
64

65
      return request(app.getHttpServer())
66
        .get('/asset/search?email=test@test.com')
67
        .expect(200)
68
    })
69
  })
70

71
  describe('Auth required endpoints', () => {
72
    it('should fail getMirrorPublicLibraryAssets without firebase auth', () => {
73
      return request(app.getHttpServer()).get('/asset/library').expect(403)
74
    })
75

76
    it('should fail create without firebase auth', () => {
77
      return request(app.getHttpServer()).post('/asset').expect(403)
78
    })
79

80
    it('should fail getAssetsForMe without firebase auth', () => {
81
      return request(app.getHttpServer()).get('/asset/me').expect(403)
82
    })
83

84
    it('should fail findAllForUser without firebase auth', () => {
85
      return request(app.getHttpServer())
86
        .get('/asset/user/test-asset-id')
87
        .expect(403)
88
    })
89

90
    it('should fail findOne without firebase auth', () => {
91
      return request(app.getHttpServer())
92
        .get('/asset/test-asset-id')
93
        .expect(403)
94
    })
95

96
    it('should fail update without firebase auth', () => {
97
      return request(app.getHttpServer())
98
        .patch('/asset/test-asset-id')
99
        .expect(403)
100
    })
101

102
    it('should fail remove without firebase auth', () => {
103
      return request(app.getHttpServer())
104
        .delete('/asset/test-asset-id')
105
        .expect(403)
106
    })
107

108
    it('should fail upload without firebase auth', () => {
109
      return request(app.getHttpServer())
110
        .post('/asset/test-asset-id/upload')
111
        .expect(403)
112
    })
113

114
    it('should fail uploadPublic without firebase auth', () => {
115
      return request(app.getHttpServer())
116
        .post('/asset/test-asset-id/upload/public')
117
        .expect(403)
118
    })
119
  })
120
})
121

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.