Skip to content

Unit test #11

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

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f235672
Enable workSchedule API for SDK
tkla Jun 1, 2022
89c0956
Update workSchedule name and description
tkla Jun 3, 2022
1d68fa8
Add GET workSchedules request to EnvoyAPI
tkla Jun 3, 2022
5689d31
Adjusted GET workSchedules to use its own request options rather than…
tkla Jun 3, 2022
00b4988
Add companies api to EnvoyAPI
tkla Jun 3, 2022
61c2150
Add GET /entry
tkla Jun 3, 2022
0a8ef1a
Add GET, POST, and PATCH createEntry
tkla Jun 6, 2022
02964bc
Add GET entries by date
tkla Jun 6, 2022
f768af5
Updated Urls for workschedule APIs, these will possibly be deprecated…
tkla Jun 7, 2022
a21d4c4
Add DELETE work schedule
tkla Jun 7, 2022
af279c9
Add check in and check out for work schedule
tkla Jun 7, 2022
828546a
Add GET invites for both singular and multiple invites. Updated new A…
tkla Jun 7, 2022
69702c3
Add createInviteV1 to create invites using new route
tkla Jun 7, 2022
9295232
Update createInviteV1 to send back request body
tkla Jun 8, 2022
7fd24d3
Add updateInviteV1
tkla Jun 8, 2022
3f580af
Add removeInviteV1
tkla Jun 8, 2022
eb54076
Add axios package.
tkla Jun 8, 2022
db82bd4
Add reservations APIs
tkla Jun 8, 2022
3e9c9df
Add space APIs
tkla Jun 8, 2022
259ad68
Change deleteWorkSchedule back to async class method
tkla Jun 10, 2022
e76b04b
Add externalAuthLogin
tkla Jul 1, 2022
7f84846
Add getAccessTokenFromAuth and refreshAccessToken methods to EnvoyAPI
tkla Jul 5, 2022
d728d17
Add EnvoyAPI.login() test cases for success
tkla Jul 19, 2022
654b031
Add fail test cases to EnvoyAPI.login()
tkla Jul 19, 2022
21c63bc
Add location api unit tests
tkla Jul 20, 2022
f2035b2
Add test cases for flows and company. Add employees api call
tkla Jul 20, 2022
f56a98e
Add new Employees api to EnvoyAPI and add getSignInFields. Employees …
tkla Jul 21, 2022
8f4f2a0
Add flowBadge, locationEmployees, employees, signInPage tests
tkla Jul 21, 2022
7ef8b12
Add entries tests
tkla Jul 22, 2022
8e28d3e
Add work schedules tests. Updated createWorkSchedule to not require a…
tkla Jul 22, 2022
8703c37
Add workScheduleDelete tests
tkla Jul 26, 2022
10ab102
Add checkIn and checkOut workschedule tests. Update reservations() to…
tkla Aug 1, 2022
a96a12c
Add Invites, reservations, spaces, refreshAccessToken, getDataFromBod…
tkla Aug 1, 2022
1193c44
Add more tests for deprecated methods
tkla Aug 3, 2022
c57551a
Add EnvoyPluginSDK tests
tkla Aug 3, 2022
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
Prev Previous commit
Next Next commit
Add test cases for flows and company. Add employees api call
  • Loading branch information
tkla committed Jul 20, 2022
commit f2035b267c7942a5f0383074d2aa4974c8e172ae
51 changes: 51 additions & 0 deletions lib/EnvoyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class EnvoyAPI {
return EnvoyAPI.getDataFromBody(body);
}

/**
* Deprecated
*/
async company() {

const body = await this.request({
Expand Down Expand Up @@ -145,6 +148,9 @@ class EnvoyAPI {
return EnvoyAPI.getDataFromBody(body);
}

/**
* Deprecated
*/
async me() {

const body = await this.request({
Expand All @@ -154,6 +160,9 @@ class EnvoyAPI {
return EnvoyAPI.getDataFromBody(body);
}

/**
* Deprecated
*/
async companyRoles(userId) {

const body = await this.request({
Expand All @@ -163,6 +172,48 @@ class EnvoyAPI {
return EnvoyAPI.getDataFromBody(body, data => Array.isArray(data));
}

/**
* Fetches the employees for this location.
*
* @param {string | number | object} params
* @param {{
* id: {string} A comma-separated list of IDs.
* name: {string} The full name of the employee. Allows partial search (e.g., "Ro"). Special characters and spaces should be URL-encoded
* email: {string} Email address. Allows partial search.
* page: {number} Controls which page to look at in the results
* perPage: {number} Controls how many results to show in each page of the results. Use with page.
* sort: {string} Controls which field should be compared to sort the results. Possible values are "NAME" or "EMAIL". Use with order.
* order: {string} Controls the sorting direction. Possible values are "ASC" and "DESC". Use with sort.
* }} params Optional params if not looking up directly by ID.
* @returns {Promise<EnvoyObject[]>}
*/
async employees(params = {}) {
let employeeUrl = this.newUrl + '/employees';
if (typeof params === 'string' || typeof params === 'number') {
employeeUrl = employeeUrl + `/${params}`;
}

var options = {
method: 'GET',
url: employeeUrl,
headers: {
Authorization: 'Bearer ' + this.token
},
qs: params, // If params is not an object, query params will be ignored as it is assumed you will be doing a lookup by id.
json: true
};

const body = await request(options, function (error, response) {
if (error) throw new Error(error);
response.body;
});

return EnvoyAPI.getDataFromBody(body);
}

/**
* Deprecated. Use employees() instead.
*/
async employee(companyRoleId) {

const body = await this.request({
Expand Down
45 changes: 34 additions & 11 deletions lib/test/EnvoyAPI.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const EnvoyAPI = require('../EnvoyAPI');
const request = require('request');
// const { expect } = require('chai');
let envoy = null;
let envoyNoScopes = null;

Expand Down Expand Up @@ -102,7 +101,7 @@ describe('EnvoyAPI.login()', () => {
describe('EnvoyAPI Instantiation', () => {
beforeAll(async () => {
let accessToken = await getAccessToken();
// console.log(accessToken.access_token);
console.log("USING ACCESS TOKEN: ", accessToken.access_token);
envoy = new EnvoyAPI(accessToken.access_token);
})

Expand All @@ -122,7 +121,7 @@ describe('EnvoyAPI Instantiation', () => {
})
})

describe('EnvoyAPI methods', () => {
describe('EnvoyAPI methods', () => {
describe('Locations', () => {
let locations = null;
let location = null;
Expand All @@ -148,16 +147,40 @@ describe('EnvoyAPI methods', () => {
})

describe('Flows', () => {
let flows = null;
let flow = null;

beforeAll(async () => {
flows = await envoy.flows(143497);
// flow = await envoy.flow();
})
it('flows() should return all visitor flows given a location Id', async () => {
let flows = await envoy.flows(143497);
expect(flows[0].id).toEqual('295831');
});

it('flows() should return an empty array if location can\'t be found', async () => {
flows = await envoy.flows(999999);
expect(flows).toEqual([]);
});

it('should return all visitor flows given a location id', () => {
console.log(flows);
it('flow() should return a single flow given a flow Id', async () => {
let flow = await envoy.flow(295831);
expect(flow.id).toEqual('295831');
});

it('flow() should return status code 404 if flow id can\t be found', async () => {
try {
await envoy.flow(999909999);
} catch (err) {
flow = err;
}

expect(flow.statusCode).toEqual(404);
});
})

describe('Company', () => {
it('companies() should retrieve details for companies scoped to the access token.', async () => {
let company = await envoy.companies();
expect(company[0].id).toEqual('110090');
})
})



})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --setupFiles dotenv/config"
"test": "jest --coverage --setupFiles dotenv/config"
},
"repository": {
"type": "git",
Expand Down