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 flowBadge, locationEmployees, employees, signInPage tests
  • Loading branch information
tkla committed Jul 21, 2022
commit 8f4f2a0325cb70d40347e8677d999b0ac060a147
31 changes: 21 additions & 10 deletions lib/EnvoyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,28 @@ class EnvoyAPI {

/**
* Import employee records to the Employee Directory. The file headers must be in the following order, Full Name, Email, Mobile Number, Assistants Email.
* If your csv does not contain email entries, it will override the previous employee directory in full.
* Possibly deprecated? This route doesn't seem to exist anymore.
* Your .csv must list one employee per line, contain a unique email address for each employee, and match the format below.
* Mobile numbers and assistant email are optional.
* Legacy API, this still works but will not be supported.
* @param {file} file
* @param {string} api_key
* @returns
*/
async importEmployeeRecords(file, api_key) {
async importEmployeeRecords(file) {
var options = {
'method': 'GET',
'url': `https://app.envoy.com/api/configuration/employee_list/${api_key}`,
'method': 'POST',
'url': `https://app.envoy.com/api/configuration/employee_list`,
'headers': {
'Authorization': 'Bearer ' + this.token
},
body: file,
formData: {
'file': {
'value': file,
'options': {
'filename': '',
'contentType': null
}
}
},
json: true,
};

Expand All @@ -251,13 +259,14 @@ class EnvoyAPI {
response.body;
});

return EnvoyAPI.getDataFromBody(body);
return body;
}


/**
* Deprecated. Use employees() and filter by location Ids of employees returned.
* See employees() for list of optional params.
* Fetches the employees for this location.
*
* @param {string|number} locationId
* @param {{}} params
* @returns {Promise<EnvoyObject[]>}
Expand All @@ -273,8 +282,9 @@ class EnvoyAPI {
}

/**
* Deprecated. Use employees() instead.
* Fetches an employee.
*
*
* @param {string|number} employeeId
* @returns {Promise<EnvoyObject>}
*/
Expand Down Expand Up @@ -303,6 +313,7 @@ class EnvoyAPI {
}

/**
* Deprecated.
* Fetches the sign-in page details for this flow.
*
* @param {string|number} flowId
Expand Down
103 changes: 102 additions & 1 deletion lib/test/EnvoyAPI.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const EnvoyAPI = require('../EnvoyAPI');
const request = require('request');
const fs = require('fs');
let envoy = null;
let envoyNoScopes = null;

Expand All @@ -8,14 +9,22 @@ const TOKEN_SCOPE = [
'locations.read',
'companies.read',
'flows.read',
'badges.read',
'invites.read',
'invites.write',
'employees.read',
'employees.write',
'entries.read',
'entries.write',
'agreements.write',
'reservations.read',
'reservations.write',
'spaces.read',
'work-schedules.read',
'work-schedules.write',
'sign-in-fields.read',
'sign-in-fields.write',
'sign-in-field-pages.read',
]

/**
Expand Down Expand Up @@ -296,5 +305,97 @@ describe('EnvoyAPI methods', () => {
// });
// });

describe('')
/* Don't run this test as it will overwrite all employees with your uploaded csv file. This is also a deprecated API.
describe('(Deprecated) Employee Import', () => {
it('Should import employees from a csv file.', async () => {
let file = fs.createReadStream('./lib/test/resource/employees-export.csv');
let empImport = await envoy.importEmployeeRecords(file);

expect(empImport.message).toEqual('File uploaded successfully. Check /api/configuration/import_status for status.');
})
});
*/

// describe('(Deprecated) locationEmployees', () => {
// it('should return employees from a location.', async () => {
// let employees = await envoy.locationEmployees(143497, {
// //Optional params.
// email: '[email protected]'
// });
// expect(employees[0].type).toEqual('employees');
// })

// it('should return status 404 if location can\'t be found.', async () => {
// let errMsg = null;

// try {
// await envoy.locationEmployees(999999);
// } catch(err) {
// errMsg = err.statusCode;
// }

// expect(errMsg).toEqual(404);
// })
// });

// describe('(Deprecated) flowBadge', () => {
// it('should return badge for this flow.', async () => {
// let flow = await envoy.flowBadge(295831);

// expect(flow.id).toEqual('226107');
// })

// it('should return status 404 if flow can\'t be found.', async () => {
// let errMsg = null;

// try {
// await envoy.flowBadge(999999);
// } catch(err) {
// errMsg = err.statusCode;
// }

// expect(errMsg).toEqual(404);
// })

// });

// describe('(Deprecated) signInPage', () => {
// it('should return sign-in page details for this flow', async () => {
// let page = await envoy.signInPage(295831);
// expect(page.type).toEqual('sign-in-field-pages');
// })

// it('should return status 404 if flow can\'t be found.', async () => {
// let errMsg = null;

// try {
// await envoy.signInPage(999999);
// } catch(err) {
// errMsg = err.statusCode;
// }

// expect(errMsg).toEqual(404);
// })

// });

describe('(Deprecated) signInFields', () => {
it('should return the sign-in fields for this page', async () => {
let page = await envoy.signInFields(1433967);
expect(page.type).toEqual('sign-in-field-pages');
})

it('should return status 404 if flow can\'t be found.', async () => {
let errMsg = null;

try {
await envoy.signInFields(999999);
} catch(err) {
errMsg = err.statusCode;
}

expect(errMsg).toEqual(404);
})

});
})