Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 71 additions & 51 deletions __tests__/AppBaseClientTest.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
const appbase = require('..');
const appbase = require("..");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have formatting changes?


const { uuidv4 } = require('../__mocks__');
const { uuidv4 } = require("../__mocks__");

describe('#AppBase_Client', () => {
test('should create appbase client', () => {
describe("#AppBase_Client", () => {
test("should create appbase client", () => {
const client = appbase({
url: 'https://appbase-demo-ansible-abxiydt-arc.searchbase.io',
app: 'appbasejs-test-app',
credentials: 'f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f',
url: "https://appbase-demo-ansible-abxiydt-arc.searchbase.io",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
expect(client).toEqual({
url: 'appbase-demo-ansible-abxiydt-arc.searchbase.io',
protocol: 'https',
app: 'appbasejs-test-app',
credentials: 'f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f',
url: "appbase-demo-ansible-abxiydt-arc.searchbase.io",
protocol: "https",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
});
test('should throw url missing error', () => {
test("should throw url missing error", () => {
try {
appbase({
app: 'appbasejs-test-app',
credentials: 'f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f',
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual('URL not present in options.');
expect(e.message).toEqual("URL not present in options.");
}
});
test('should throw app missing error', () => {
test("should throw app missing error", () => {
try {
appbase({
url: 'https://appbase-demo-ansible-abxiydt-arc.searchbase.io',
credentials: 'f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f',
url: "https://appbase-demo-ansible-abxiydt-arc.searchbase.io",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual('App name is not present in options.');
expect(e.message).toEqual("App name is not present in options.");
}
});
test('should throw protocol missing error', () => {
test("should throw protocol missing error", () => {
try {
appbase({
url: 'appbase-demo-ansible-abxiydt-arc.searchbase.io',
app: 'appbasejs-test-app',
credentials: 'f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f',
url: "appbase-demo-ansible-abxiydt-arc.searchbase.io",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual(
'Protocol is not present in url. URL should be of the form https://appbase-demo-ansible-abxiydt-arc.searchbase.io'
"Protocol is not present in url. URL should be of the form https://appbase-demo-ansible-abxiydt-arc.searchbase.io"
);
}
});
test('should throw credentials missing error', () => {
test("should throw credentials missing error", () => {
try {
appbase({
url: 'https://scalr.api.appbase.io',
app: 'appbasejs-test-app',
url: "https://scalr.api.appbase.io",
app: "appbasejs-test-app",
});
expect(true).toBe(false);
} catch (e) {
expect(e.message).toEqual(
'Authentication information is not present. Did you add credentials?'
"Authentication information is not present. Did you add credentials?"
);
}
});
test('should set headers', () => {
test("should set headers", () => {
const client = appbase({
url: 'https://appbase-demo-ansible-abxiydt-arc.searchbase.io',
app: 'appbasejs-test-app',
credentials: 'f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f',
url: "https://appbase-demo-ansible-abxiydt-arc.searchbase.io",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
client.setHeaders({
authorization: 'test-authorize',
'x-search-key': '美女',
authorization: "test-authorize",
"x-search-key": "美女",
});
expect(client).toEqual({
url: 'appbase-demo-ansible-abxiydt-arc.searchbase.io',
protocol: 'https',
app: 'appbasejs-test-app',
credentials: 'f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f',
url: "appbase-demo-ansible-abxiydt-arc.searchbase.io",
protocol: "https",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
headers: {
authorization: 'test-authorize',
'x-search-key': '美女',
authorization: "test-authorize",
"x-search-key": "美女",
},
});
});
test('should set X-Enable-Telemetry header', () => {
test("should set X-Enable-Telemetry header", () => {
const client = appbase({
url: 'https://appbase-demo-ansible-abxiydt-arc.searchbase.io',
app: 'appbasejs-test-app',
credentials: 'f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f',
url: "https://appbase-demo-ansible-abxiydt-arc.searchbase.io",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
enableTelemetry: false,
});
expect(client).toEqual({
Expand All @@ -101,25 +101,45 @@ describe('#AppBase_Client', () => {
enableTelemetry: false,
});
});
test('should call transformRequest before fetch', async () => {
test("should call transformRequest before fetch", async () => {
const client = appbase({
url: 'https://appbase-demo-ansible-abxiydt-arc.searchbase.io',
app: 'appbasejs-test-app',
credentials: 'f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f',
url: "https://appbase-demo-ansible-abxiydt-arc.searchbase.io",
app: "appbasejs-test-app",
credentials: "f1a7b4562098:35fed6ff-4a19-4387-a188-7cdfe759c40f",
});
client.transformRequest = (request) => {
expect(true).toBe(true);
return request;
};
const id = uuidv4();
const tweet = {
user: 'olivere',
message: 'Welcome to Golang and Elasticsearch.',
user: "olivere",
message: "Welcome to Golang and Elasticsearch.",
};
client.index({
type: 'tweet_transform_error',
type: "tweet_transform_error",
id,
body: tweet,
});
});
test("should create appbase client with mongodb", () => {
const client = appbase({
url: "https://us-east-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/public-demo-skxjb/service/http_endpoint/incoming_webhook/reactivesearch",
app: "appbasejs-test-app",
mongodb: {
db: "test_db",
collection: "test_collection",
},
});
expect(client).toEqual({
url: "https://us-east-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/public-demo-skxjb/service/http_endpoint/incoming_webhook/reactivesearch",
protocol: "https",
credentials: null,
app: "appbasejs-test-app",
mongodb: {
db: "test_db",
collection: "test_collection",
},
});
});
});
Loading