Skip to content

Commit c64a7ac

Browse files
committed
feat: add SongWebhookService mock and formatDuration utility function
1 parent 114266d commit c64a7ac

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

server/src/song/song.service.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from './entity/song.entity';
2020
import { SongUploadService } from './song-upload/song-upload.service';
2121
import { SongService } from './song.service';
22+
import { SongWebhookService } from './song-webhook/song-webhook.service';
2223

2324
const mockFileService = {
2425
deleteSong: jest.fn(),
@@ -30,6 +31,14 @@ const mockSongUploadService = {
3031
processSongPatch: jest.fn(),
3132
};
3233

34+
const mockSongWebhookService = {
35+
syncAllSongsWebhook: jest.fn(),
36+
postSongWebhook: jest.fn(),
37+
updateSongWebhook: jest.fn(),
38+
deleteSongWebhook: jest.fn(),
39+
syncSongWebhook: jest.fn(),
40+
};
41+
3342
describe('SongService', () => {
3443
let service: SongService;
3544
let fileService: FileService;
@@ -40,6 +49,10 @@ describe('SongService', () => {
4049
const module: TestingModule = await Test.createTestingModule({
4150
providers: [
4251
SongService,
52+
{
53+
provide: SongWebhookService,
54+
useValue: mockSongWebhookService,
55+
},
4356
{
4457
provide: getModelToken(SongEntity.name),
4558
useValue: mongoose.model(SongEntity.name, SongSchema),

server/src/song/song.util.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import { UploadConst } from '@shared/validation/song/constants';
2-
import { formatDuration } from '@web/src/modules/shared/util/format';
2+
33
import { customAlphabet } from 'nanoid';
44

55
import { SongWithUser } from './entity/song.entity';
66

7+
export const formatDuration = (totalSeconds: number) => {
8+
const minutes = Math.floor(Math.ceil(totalSeconds) / 60);
9+
const seconds = Math.ceil(totalSeconds) % 60;
10+
11+
const formattedTime = `${minutes.toFixed().padStart(1, '0')}:${seconds
12+
.toFixed()
13+
.padStart(2, '0')}`;
14+
15+
return formattedTime;
16+
};
17+
718
export function removeExtraSpaces(input: string): string {
819
return input
920
.replace(/ +/g, ' ') // replace multiple spaces with one space

0 commit comments

Comments
 (0)