Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdaGnsrn committed Nov 6, 2023
1 parent 7788212 commit 9ddc43e
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/app.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const elevenLabs = require('../index');
const Storage = require('../utils/Storage');

describe('Static Functions Unit Test', () => {
test('setApiKey() function should set the API key in the Storage class', () => {
const apiKey = 'YOUR_API_KEY';
elevenLabs.setApiKey(apiKey);
expect(Storage.apiKey).toBe(apiKey)
})
});
89 changes: 89 additions & 0 deletions tests/methods.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const elevenLabs = require('../index');
const fs = require("fs");

require('dotenv').config();
const apiKey = process.env.ELEVENLABS_API_KEY;
let voiceId = null;

describe('Methods Unit Test', () => {
beforeAll(() => {
if (!apiKey) {
throw new Error('ELEVENLABS_API_KEY environment variable is not set');
}

elevenLabs.setApiKey(apiKey);
});

// Models
test("getModels() function", async () => {
const models = await elevenLabs.getModels();
expect(models).toBeInstanceOf(Array);
expect(models.length).toBeGreaterThan(0);
});

// Voices
test("getVoices() function", async () => {
const voices = await elevenLabs.getVoices();
expect(voices).toBeInstanceOf(Array);
expect(voices.length).toBeGreaterThan(0);
voiceId = voices[0]['voice_id'];
});
test("getDefaultVoiceSettings() function", async () => {
const defaultVoiceSettings = await elevenLabs.getDefaultVoiceSettings();
expect(defaultVoiceSettings).toBeInstanceOf(Object);
expect(defaultVoiceSettings).toHaveProperty('stability');
expect(defaultVoiceSettings).toHaveProperty('similarity_boost');
expect(defaultVoiceSettings).toHaveProperty('style');
expect(defaultVoiceSettings).toHaveProperty('use_speaker_boost');
});
test("getVoiceSettings() function", async () => {
const defaultVoiceSettings = await elevenLabs.getVoiceSettings(voiceId);
expect(defaultVoiceSettings).toBeInstanceOf(Object);
expect(defaultVoiceSettings).toHaveProperty('stability');
expect(defaultVoiceSettings).toHaveProperty('similarity_boost');
expect(defaultVoiceSettings).toHaveProperty('style');
expect(defaultVoiceSettings).toHaveProperty('use_speaker_boost');
});
test("getVoice() function", async () => {
const defaultVoiceSettings = await elevenLabs.getVoice(voiceId, true);
expect(defaultVoiceSettings).toBeInstanceOf(Object);
expect(defaultVoiceSettings).toHaveProperty('voice_id');
expect(defaultVoiceSettings).toHaveProperty('name');
expect(defaultVoiceSettings).toHaveProperty('settings');

const settings = defaultVoiceSettings['settings'];
expect(settings).toHaveProperty('stability');
expect(settings).toHaveProperty('similarity_boost');
expect(settings).toHaveProperty('style');
expect(settings).toHaveProperty('use_speaker_boost');
});

// Users
test("getUser() function", async () => {
const users = await elevenLabs.getUser();
expect(users).toBeInstanceOf(Object);
});
test("getUserSubscription() function", async () => {
const users = await elevenLabs.getUserSubscription();
expect(users).toBeInstanceOf(Object);
expect(users).toHaveProperty('status');
});

// TextToSpeech
test("textToSpeech() function", async () => {
const response = await elevenLabs.textToSpeech(voiceId, 'H');

expect(response).toBeDefined();

expect(response).toHaveProperty('pipe');
expect(response).toHaveProperty('saveFile');

expect(response.saveFile).toBeInstanceOf(Function);

await response.saveFile('test.mp3');
fs.access('test.mp3', fs.constants.F_OK, (err) => {
expect(err).toBeNull();
});
fs.unlinkSync('test.mp3');
});
});

0 comments on commit 9ddc43e

Please sign in to comment.