@lableb/javascript-sdk
Version:
Lableb cloud search client for javascript
164 lines (101 loc) • 3.71 kB
text/typescript
import { MESSAGES } from "../../config/messages";
import { LablebClient } from "../lableb-client/lableb-client";
describe('Test Auth', () => {
test('Search at lableb cloud without api key', async () => {
try {
const lablebClient = LablebClient({
platformName: process.env.PLATFORM_NAME,
});
await lablebClient.searchById({
id: 'hello',
APIKey: '',
});
throw new Error('unexpected');
} catch (error) {
expect(error.message).toEqual(MESSAGES.API_KEY_IS_REQUIRED);
}
});
});
describe('Test Search Request', () => {
test('Search at lableb cloud', async () => {
const lablebClient = LablebClient({
APIKey: process.env.API_KEY,
platformName: process.env.PLATFORM_NAME,
});
const { code, response, time } = await lablebClient.searchById({
id: 'hello',
});
expect(code).toBe(200);
expect(time).toBeGreaterThan(0);
expect(typeof response.id).toBe('string');
expect(typeof response).toEqual('object');
});
test('Search at lableb cloud where options passed to inner search', async () => {
const lablebClient = LablebClient();
const { code, response, time } = await lablebClient.searchById({
id: 'hello',
APIKey: process.env.API_KEY,
platformName: process.env.PLATFORM_NAME,
});
expect(code).toBe(200);
expect(time).toBeGreaterThan(0);
expect(typeof response.id).toBe('string');
expect(typeof response).toEqual('object');
});
test('Search at lableb cloud with all optional options', async () => {
const lablebClient = LablebClient({
APIKey: process.env.API_KEY,
platformName: process.env.PLATFORM_NAME,
});
const { code, response, time } = await lablebClient.searchById({
id: 'hello',
limit: 2,
sessionId: '92492mfa',
skip: 0,
sort: 'title asc',
userId: '42',
userIp: '172.65.23.22',
userCountry: 'AE',
});
expect(code).toBe(200);
expect(time).toBeGreaterThan(0);
expect(typeof response.id).toBe('string');
expect(typeof response).toEqual('object');
});
test('Search at lableb cloud with all optional options overridden', async () => {
const lablebClient = LablebClient({
APIKey: process.env.API_KEY,
platformName: process.env.PLATFORM_NAME,
sessionId: '92492mfa',
userId: '15',
userCountry: 'AE',
});
const { code, response, time } = await lablebClient.searchById({
id: 'hello',
limit: 2,
skip: 0,
sort: 'title asc',
userIp: '172.65.23.22',
userCountry: 'IQ',
});
expect(code).toBe(200);
expect(time).toBeGreaterThan(0);
expect(typeof response.id).toBe('string');
expect(typeof response).toEqual('object');
});
});
describe('Bad Inputs', () => {
test('Search at lableb cloud with no id', async () => {
try {
const lablebClient = LablebClient({
APIKey: process.env.API_KEY,
platformName: process.env.PLATFORM_NAME,
});
await lablebClient.searchById({
id: '',
});
} catch (error) {
expect(error.message).toEqual(MESSAGES.DOCUMENT_ID_IS_REQUIRED);
}
});
});