-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |