|
1 | 1 | import { InternalServerErrorException, NotFoundException, ServiceUnavailableException } from '@nestjs/common';
|
2 | 2 | import { Test, TestingModule } from '@nestjs/testing';
|
3 | 3 | import { EventEmitter2 } from '@nestjs/event-emitter';
|
4 |
| -import { omit, forIn, get, update } from 'lodash'; |
5 |
| -import { plainToClass } from 'class-transformer'; |
| 4 | +import { omit, get, update } from 'lodash'; |
6 | 5 |
|
7 | 6 | import { classToClass } from 'src/utils';
|
8 | 7 | import {
|
@@ -33,7 +32,7 @@ describe('DatabaseService', () => {
|
33 | 32 | 'sshOptions.passphrase',
|
34 | 33 | 'sshOptions.privateKey',
|
35 | 34 | 'sentinelMaster.password',
|
36 |
| - ] |
| 35 | + ]; |
37 | 36 |
|
38 | 37 | beforeEach(async () => {
|
39 | 38 | jest.clearAllMocks();
|
@@ -128,19 +127,22 @@ describe('DatabaseService', () => {
|
128 | 127 | });
|
129 | 128 |
|
130 | 129 | describe('update', () => {
|
131 |
| - it.skip('should update existing database and send analytics event', async () => { |
132 |
| - expect(await service.update( |
| 130 | + it('should update existing database and send analytics event', async () => { |
| 131 | + databaseRepository.update.mockReturnValue({ |
| 132 | + ...mockDatabase, |
| 133 | + port: 6380, |
| 134 | + password: 'password', |
| 135 | + provider: 'LOCALHOST', |
| 136 | + }); |
| 137 | + |
| 138 | + await expect(await service.update( |
133 | 139 | mockDatabase.id,
|
134 | 140 | { password: 'password', port: 6380 } as UpdateDatabaseDto,
|
135 | 141 | true,
|
136 |
| - )).toEqual(mockDatabase); |
| 142 | + )).toEqual({ ...mockDatabase, port: 6380, password: 'password' }); |
137 | 143 | expect(analytics.sendInstanceEditedEvent).toHaveBeenCalledWith(
|
138 | 144 | mockDatabase,
|
139 |
| - { |
140 |
| - ...mockDatabase, |
141 |
| - password: 'password', |
142 |
| - port: 6380, |
143 |
| - }, |
| 145 | + { ...mockDatabase, port: 6380, password: 'password' }, |
144 | 146 | true,
|
145 | 147 | );
|
146 | 148 | });
|
@@ -199,48 +201,48 @@ describe('DatabaseService', () => {
|
199 | 201 | it('should return multiple databases without Standalone secrets', async () => {
|
200 | 202 | databaseRepository.get.mockResolvedValueOnce(mockDatabaseWithTlsAuth);
|
201 | 203 |
|
202 |
| - expect(await service.export([mockDatabaseWithTlsAuth.id], false)).toEqual([classToClass(ExportDatabase,omit(mockDatabaseWithTlsAuth, 'password'))]); |
203 |
| - }) |
| 204 | + expect(await service.export([mockDatabaseWithTlsAuth.id], false)).toEqual([classToClass(ExportDatabase, omit(mockDatabaseWithTlsAuth, 'password'))]); |
| 205 | + }); |
204 | 206 |
|
205 | 207 | it('should return multiple databases without SSH secrets', async () => {
|
206 | 208 | // remove SSH secrets
|
207 |
| - const mockDatabaseWithSshPrivateKeyTemp = {...mockDatabaseWithSshPrivateKey} |
| 209 | + const mockDatabaseWithSshPrivateKeyTemp = { ...mockDatabaseWithSshPrivateKey }; |
208 | 210 | exportSecurityFields.forEach((field) => {
|
209 |
| - if(get(mockDatabaseWithSshPrivateKeyTemp, field)) { |
210 |
| - update(mockDatabaseWithSshPrivateKeyTemp, field, () => null) |
| 211 | + if (get(mockDatabaseWithSshPrivateKeyTemp, field)) { |
| 212 | + update(mockDatabaseWithSshPrivateKeyTemp, field, () => null); |
211 | 213 | }
|
212 |
| - }) |
| 214 | + }); |
213 | 215 |
|
214 | 216 | databaseRepository.get.mockResolvedValueOnce(mockDatabaseWithSshPrivateKey);
|
215 |
| - expect(await service.export([mockDatabaseWithSshPrivateKey.id], false)).toEqual([classToClass(ExportDatabase, mockDatabaseWithSshPrivateKeyTemp)]) |
216 |
| - }) |
| 217 | + expect(await service.export([mockDatabaseWithSshPrivateKey.id], false)).toEqual([classToClass(ExportDatabase, mockDatabaseWithSshPrivateKeyTemp)]); |
| 218 | + }); |
217 | 219 |
|
218 | 220 | it('should return multiple databases without Sentinel secrets', async () => {
|
219 | 221 | // remove secrets
|
220 |
| - const mockSentinelDatabaseWithTlsAuthTemp = {...mockSentinelDatabaseWithTlsAuth} |
| 222 | + const mockSentinelDatabaseWithTlsAuthTemp = { ...mockSentinelDatabaseWithTlsAuth }; |
221 | 223 | exportSecurityFields.forEach((field) => {
|
222 |
| - if(get(mockSentinelDatabaseWithTlsAuthTemp, field)) { |
223 |
| - update(mockSentinelDatabaseWithTlsAuthTemp, field, () => null) |
| 224 | + if (get(mockSentinelDatabaseWithTlsAuthTemp, field)) { |
| 225 | + update(mockSentinelDatabaseWithTlsAuthTemp, field, () => null); |
224 | 226 | }
|
225 |
| - }) |
| 227 | + }); |
226 | 228 |
|
227 | 229 | databaseRepository.get.mockResolvedValue(mockSentinelDatabaseWithTlsAuth);
|
228 | 230 |
|
229 |
| - expect(await service.export([mockSentinelDatabaseWithTlsAuth.id], false)).toEqual([classToClass(ExportDatabase, omit(mockSentinelDatabaseWithTlsAuthTemp, 'password'))]) |
| 231 | + expect(await service.export([mockSentinelDatabaseWithTlsAuth.id], false)).toEqual([classToClass(ExportDatabase, omit(mockSentinelDatabaseWithTlsAuthTemp, 'password'))]); |
230 | 232 | });
|
231 | 233 |
|
232 | 234 | it('should return multiple databases with secrets', async () => {
|
233 | 235 | // Standalone
|
234 | 236 | databaseRepository.get.mockResolvedValueOnce(mockDatabaseWithTls);
|
235 |
| - expect(await service.export([mockDatabaseWithTls.id], true)).toEqual([classToClass(ExportDatabase,mockDatabaseWithTls)]); |
| 237 | + expect(await service.export([mockDatabaseWithTls.id], true)).toEqual([classToClass(ExportDatabase, mockDatabaseWithTls)]); |
236 | 238 |
|
237 | 239 | // SSH
|
238 | 240 | databaseRepository.get.mockResolvedValueOnce(mockDatabaseWithSshPrivateKey);
|
239 |
| - expect(await service.export([mockDatabaseWithSshPrivateKey.id], true)).toEqual([classToClass(ExportDatabase, mockDatabaseWithSshPrivateKey)]) |
| 241 | + expect(await service.export([mockDatabaseWithSshPrivateKey.id], true)).toEqual([classToClass(ExportDatabase, mockDatabaseWithSshPrivateKey)]); |
240 | 242 |
|
241 | 243 | // Sentinel
|
242 | 244 | databaseRepository.get.mockResolvedValueOnce(mockSentinelDatabaseWithTlsAuth);
|
243 |
| - expect(await service.export([mockSentinelDatabaseWithTlsAuth.id], true)).toEqual([classToClass(ExportDatabase, mockSentinelDatabaseWithTlsAuth)]) |
| 245 | + expect(await service.export([mockSentinelDatabaseWithTlsAuth.id], true)).toEqual([classToClass(ExportDatabase, mockSentinelDatabaseWithTlsAuth)]); |
244 | 246 | });
|
245 | 247 |
|
246 | 248 | it('should ignore errors', async () => {
|
|
0 commit comments