Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some tests and change API request method #146

Merged
merged 1 commit into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 9 additions & 14 deletions api-module-library/slack/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,28 +473,23 @@ class Api extends OAuth2Requester {
// latest: integer, optional
// oldest: integer, optional
// inclusive: boolean, optional
async getChannelHistory(query) {
async getChannelHistory(body) {
const options = {
url: this.baseUrl + this.URLs.getChannelHistory,
body,
};
const response = await this._post(options);
return response;
}
async listChannels(query) {
const options = {
url: this.baseUrl + this.URLs.listChannels,
query,
};
const response = await this._get(options);
return response;
}

// Args:
// channel: string, required
// ts: string, required
// as_user: boolean, optional
// attachments: string, optional
// blocks: blocks[] as string, optional
// file_ids: array, optional
// link_names: boolean, optional
// metadata: string, optional
// mrkdwn: boolean, optional
// parse: string, optional
// reply_broadcast: boolean, optional
// thread_ts: string, optional
// unfurl_links: boolean, optional

// Args:
Expand Down
81 changes: 39 additions & 42 deletions api-module-library/slack/test/api.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
const { Api } = require('../api');
const Authenticator = require('@friggframework/test-environment/Authenticator');
const config = require('../defaultConfig.json');
require('dotenv').config();

describe(`Should fully test the ${config.label} API Class`, () => {
let api;
beforeAll(async () => {
const apiParams = {
client_id: process.env.HUBSPOT_CLIENT_ID,
client_secret: process.env.HUBSPOT_CLIENT_SECRET,
scope: process.env.HUBSPOT_SCOPE,
redirect_uri: `${process.env.REDIRECT_URI}/hubspot`,
};
api = new Api(apiParams);
api = new Api({ access_token: process.env.TEST_ACCESS_TOKEN });
});

afterAll(async () => {});
Expand All @@ -20,10 +15,9 @@ describe(`Should fully test the ${config.label} API Class`, () => {
it('should return auth requirements', async () => {
const authUri = await api.getAuthUri();
expect(authUri).exists;
console.log(authUri);
});

it('should generate an access_token from a code', async () => {
it.skip('should generate an access_token from a code', async () => {
const authUri = await api.getAuthUri();
const response = await Authenticator.oauth2(authUri);
const baseArr = response.base.split('/');
Expand All @@ -43,51 +37,54 @@ describe(`Should fully test the ${config.label} API Class`, () => {
expect(clientSecret).exists;
expect(redirectUri).exists;

const response = await api.getUserDetails();
const response = await api.authTest();
expect(response).toBeTruthy();
});
it('should refresh auth when token expires', async () => {
it.skip('should refresh auth when token expires', async () => {
api.access_token = 'broken';
await api.refreshToken();
expect(api.access_token).to.not.equal('broken');
});
});

describe('CRM Tests', () => {
describe('Company Tests', () => {
let company;
it('should create a new company', async () => {
const createBody = {};
const response = await api.createCompany(createBody);
expect(response).toBeTruthy();
company = response.data;
});
it('should get a list of companies', async () => {
const response = await api.listCompanies();
expect(response).toBeTruthy();
describe('Channel Tests', () => {
it('should return channels', async () => {
const channels = await api.listChannels();

expect(channels).toBeTruthy();
});
describe('Direct Message Channel Tests', () => {
let messageChannel;
let messageResponse;
beforeEach(async () => {
const userEmail = process.env.TEST_USER_EMAIL;
const userDetails = await api.lookupUserByEmail(userEmail);
messageResponse = await api.postMessage({
channel: userDetails.user.id,
text: 'Hello World!',
});
expect(messageResponse).toBeTruthy();
messageChannel = messageResponse.channel;
});
it('should get a single company', async () => {
const response = await api.getCompany(company.id);
expect(response).toBeTruthy();
afterEach(async () => {
await api.deleteMessage({
channel: messageChannel,
ts: messageResponse.ts,
asUser: true,
});
});
it('should update a company', async () => {
const updateBody = {};
const response = await api.updateCompany(
company.id,
updateBody
);
expect(response).toBeTruthy();
company = response.data;
expect(company.name).to.equal(updateBody.name);
it('should create a direct message to a user', async () => {
expect(messageResponse).toBeTruthy();
});
it('should delete a company', async () => {
const response = await api.deleteCompany(company.id);
expect(response).toBeTruthy();
it('should return channel history', async () => {
const history = await api.getChannelHistory({
channel: messageChannel,
latest: messageResponse.ts,
oldest: messageResponse.ts,
inclusive: true,
});
expect(history).toBeTruthy();
});
});
describe('Contact Tests', () => {});
describe('Deal Tests', () => {});
describe('Ticket Tests', () => {});
describe('List Tests', () => {});
});
});