Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoreilly committed Nov 17, 2024
1 parent 8709a8e commit b8441f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 67 deletions.
96 changes: 30 additions & 66 deletions src/services/DubbingAPIService.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DubbingAPIService } from "./DubbingAPIService";
import { DubbingAPIService, DubbingJSON } from "./DubbingAPIService";
import { speakerService } from "./SpeakerService";
import { matxaSynthesisProvider } from "./MatxaSynthesisProvider";

Expand Down Expand Up @@ -30,39 +30,37 @@ describe("DubbingAPIService", () => {

describe("parseTracksFromJSON", () => {
it("should parse valid dubbing JSON data", () => {
const mockData = {
utterances: [
{
id: "1",
start: 0,
end: 5,
speaker_id: "SPEAKER_01",
path: "path/to/audio.mp3",
text: "Hello, world!",
for_dubbing: true,
ssml_gender: "Female",
translated_text: "Hola, mundo!",
assigned_voice: "voice1",
pitch: 0,
speed: 1,
volume_gain_db: 0,
dubbed_path: "path/to/dubbed/audio.mp3",
chunk_size: 150,
},
],
source_language: "en",
};
const mockData: DubbingJSON[] = [
{
id: 1,
start: 0,
end: 5,
speaker_id: "SPEAKER_01",
path: "path/to/audio.mp3",
text: "Hello, world!",
for_dubbing: true,
gender: "Female",
translated_text: "Hola, mundo!",
assigned_voice: "voice1",
pitch: 0,
speed: 1,
volume_gain_db: 0,
dubbed_path: "path/to/dubbed/audio.mp3",
},
];

const result = DubbingAPIService.parseTracksFromJSON(mockData);

expect(result).toHaveLength(1);
expect(result[0]).toEqual({
id: expect.any(String),
id: 1,
start: 0,
end: 5,
speaker_id: "SPEAKER_01",
path: "path/to/audio.mp3",
text: "Hello, world!",
original_text: "Hello, world!",
original_translated_text: "Hola, mundo!",
for_dubbing: true,
ssml_gender: "Female",
translated_text: "Hola, mundo!",
Expand All @@ -81,17 +79,14 @@ describe("DubbingAPIService", () => {
});

it("should handle missing properties", () => {
const mockData = {
utterances: [
{
id: "1",
start: 0,
end: 5,
speaker_id: "SPEAKER_01",
},
],
source_language: "en",
};
const mockData = [
{
id: "1",
start: 0,
end: 5,
speaker_id: "SPEAKER_01",
},
];

const result = DubbingAPIService.parseTracksFromJSON(mockData);

Expand Down Expand Up @@ -129,37 +124,6 @@ describe("DubbingAPIService", () => {
});
});

// You might want to add more tests for loadVideoFromUUID and loadTracksFromUUID
// However, these functions make API calls, so you'd need to mock the fetch function
// Here's an example of how you might structure those tests:

describe("loadVideoFromUUID", () => {
it("should load video data correctly", async () => {
const mockBlob = new Blob(["test"], { type: "video/mp4" });
const mockResponse = {
ok: true,
blob: jest.fn().mockResolvedValue(mockBlob),
headers: new Headers({
"content-type": "video/mp4",
"content-disposition": 'attachment; filename="test.mp4"',
}),
};

global.fetch = jest.fn().mockResolvedValue(mockResponse);
global.URL.createObjectURL = jest.fn().mockReturnValue("blob:test-url");

const result = await DubbingAPIService.loadVideoFromUUID("test-uuid");

expect(result).toEqual({
url: "blob:test-url",
contentType: "video/mp4",
filename: "test.mp4",
});
});

// Add more tests for error cases
});

describe("loadTracksFromUUID", () => {
it("should load tracks data correctly", async () => {
const mockData = {
Expand Down
2 changes: 1 addition & 1 deletion src/services/DubbingAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getI18n } from "react-i18next";
const API_BASE_URL =
process.env.DUBBING_API_BASE_URL || "http://192.168.178.152:8700";

type DubbingJSON = {
export type DubbingJSON = {
start: number;
end: number;
speaker_id: string;
Expand Down

0 comments on commit b8441f5

Please sign in to comment.