|
| 1 | +import { Test, TestingModule } from '@nestjs/testing'; |
| 2 | +import { FileService } from './file.service'; |
| 3 | + |
| 4 | +describe('FileService', () => { |
| 5 | + let service: FileService; |
| 6 | + |
| 7 | + beforeEach(async () => { |
| 8 | + const module: TestingModule = await Test.createTestingModule({ |
| 9 | + providers: [FileService], |
| 10 | + }).compile(); |
| 11 | + |
| 12 | + service = module.get<FileService>(FileService); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should be defined', () => { |
| 16 | + expect(service).toBeDefined(); |
| 17 | + }); |
| 18 | + |
| 19 | + describe(`bufferToBase64`, () => { |
| 20 | + it(`should convert a buffer to a base64 string`, () => { |
| 21 | + const buffer = Buffer.from(`Hello, World!`); |
| 22 | + const base64 = `SGVsbG8sIFdvcmxkIQ==`; // Base64 encoded string of 'Hello, World!' |
| 23 | + |
| 24 | + const result = service.bufferToBase64(buffer); |
| 25 | + expect(result).toBe(base64); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + describe(`base64ToBuffer`, () => { |
| 30 | + it(`should convert a base64 string to a buffer`, () => { |
| 31 | + const base64 = `SGVsbG8sIFdvcmxkIQ==`; // Base64 encoded string of 'Hello, World!' |
| 32 | + const buffer = Buffer.from(`Hello, World!`); |
| 33 | + |
| 34 | + const result = service.base64ToBuffer(base64); |
| 35 | + expect(result).toEqual(buffer); |
| 36 | + }); |
| 37 | + }); |
| 38 | +}); |
0 commit comments