Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ndustrial/contxt-sdk

Package Overview
Dependencies
Maintainers
9
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndustrial/contxt-sdk - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

src/utils/facilities/formatFacilityOptionsToServer.js

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## [v0.0.11](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.11) (2018-05-16)
**Changed**
* Facilities#getAllByOrganizationId to accept parameters to include facility grouping information
## [v0.0.10](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.10) (2018-05-01)

@@ -2,0 +8,0 @@

16

docs/Facilities.md

@@ -16,3 +16,3 @@ <a name="Facilities"></a>

* [.getAll()](#Facilities+getAll) ⇒ <code>Promise</code>
* [.getAllByOrganizationId(organizationId)](#Facilities+getAllByOrganizationId) ⇒ <code>Promise</code>
* [.getAllByOrganizationId(organizationId, [options])](#Facilities+getAllByOrganizationId) ⇒ <code>Promise</code>
* [.update(facilityId, update)](#Facilities+update) ⇒ <code>Promise</code>

@@ -80,3 +80,3 @@

| --- | --- | --- |
| facilityId | <code>number</code> | The id of the facility to update |
| facilityId | <code>number</code> | The ID of the facility to update |
| update | <code>Object</code> | An object containing the facility info for the facility |

@@ -104,3 +104,3 @@

| --- | --- | --- |
| facilityId | <code>number</code> | The id of the facility |
| facilityId | <code>number</code> | The ID of the facility |

@@ -125,3 +125,3 @@ **Example**

| --- | --- | --- |
| facilityId | <code>number</code> | The id of the facility |
| facilityId | <code>number</code> | The ID of the facility |

@@ -153,3 +153,3 @@ **Example**

### contxtSdk.facilities.getAllByOrganizationId(organizationId) ⇒ <code>Promise</code>
### contxtSdk.facilities.getAllByOrganizationId(organizationId, [options]) ⇒ <code>Promise</code>
Gets a list of all facilities that belong to a particular organization

@@ -167,6 +167,8 @@

| organizationId | <code>string</code> | UUID corresponding with an organization |
| [options] | <code>object</code> | Object containing parameters to be called with the request |
| [options.includeGroupings] | <code>boolean</code> | Boolean flag for including groupings data with each facility |
**Example**
```js
contxtSdk.facilities.getAllByOrganizationId(25)
contxtSdk.facilities.getAllByOrganizationId(25, {includeGroupings: true})
.then((facilities) => console.log(facilities));

@@ -189,3 +191,3 @@ .catch((err) => console.log(err));

| --- | --- | --- |
| facilityId | <code>number</code> | The id of the facility to update |
| facilityId | <code>number</code> | The ID of the facility to update |
| update | <code>Object</code> | An object containing the updated data for the facility |

@@ -192,0 +194,0 @@ | [update.address1] | <code>string</code> | |

@@ -79,3 +79,3 @@ <a name="Audience"></a>

| [Organization.createdAt] | <code>string</code> | ISO 8601 Extended Format date/time string |
| [Organization.id] | <code>string</code> | UUID formatted id |
| [Organization.id] | <code>string</code> | UUID formatted ID |
| [Organization.name] | <code>string</code> | |

@@ -82,0 +82,0 @@ | [Organization.updatedAt] | <code>string</code> | ISO 8601 Extended Format date/time string |

@@ -325,2 +325,6 @@ import axios from 'axios';

if (input.facility_groupings) {
facility.facility_groupings = input.facility_groupings.map(formatGroupingFromServer);
}
return facility;

@@ -347,2 +351,12 @@ }

function formatFacilityOptionsToServer(options) {
var output = _extends({}, options, {
include_groupings: options && options.includeGroupings ? options.includeGroupings : false
});
delete output.includeGroupings;
return output;
}
function formatGroupingFacilityFromServer() {

@@ -585,3 +599,3 @@ var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

if (!facilityId) {
return Promise.reject(new Error("A facility id is required to update a facility's info."));
return Promise.reject(new Error("A facility ID is required to update a facility's info."));
}

@@ -610,3 +624,3 @@

if (!facilityId) {
return Promise.reject(new Error('A facility id is required for deleting a facility'));
return Promise.reject(new Error('A facility ID is required for deleting a facility'));
}

@@ -621,3 +635,3 @@

if (!facilityId) {
return Promise.reject(new Error('A facility id is required for getting information about a facility'));
return Promise.reject(new Error('A facility ID is required for getting information about a facility'));
}

@@ -642,8 +656,12 @@

key: 'getAllByOrganizationId',
value: function getAllByOrganizationId(organizationId) {
value: function getAllByOrganizationId(organizationId, options) {
if (!organizationId) {
return Promise.reject(new Error("An organization id is required for getting a list of an organization's facilities"));
return Promise.reject(new Error("An organization ID is required for getting a list of an organization's facilities"));
}
return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/facilities').then(function (facilities) {
var params = formatFacilityOptionsToServer(options);
return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/facilities', {
params: params
}).then(function (facilities) {
return facilities.map(function (facility) {

@@ -659,3 +677,3 @@ return formatFacilityFromServer(facility);

if (!facilityId) {
return Promise.reject(new Error('A facility id is required to update a facility.'));
return Promise.reject(new Error('A facility ID is required to update a facility.'));
}

@@ -662,0 +680,0 @@

@@ -329,2 +329,6 @@ 'use strict';

if (input.facility_groupings) {
facility.facility_groupings = input.facility_groupings.map(formatGroupingFromServer);
}
return facility;

@@ -351,2 +355,12 @@ }

function formatFacilityOptionsToServer(options) {
var output = _extends({}, options, {
include_groupings: options && options.includeGroupings ? options.includeGroupings : false
});
delete output.includeGroupings;
return output;
}
function formatGroupingFacilityFromServer() {

@@ -589,3 +603,3 @@ var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

if (!facilityId) {
return Promise.reject(new Error("A facility id is required to update a facility's info."));
return Promise.reject(new Error("A facility ID is required to update a facility's info."));
}

@@ -614,3 +628,3 @@

if (!facilityId) {
return Promise.reject(new Error('A facility id is required for deleting a facility'));
return Promise.reject(new Error('A facility ID is required for deleting a facility'));
}

@@ -625,3 +639,3 @@

if (!facilityId) {
return Promise.reject(new Error('A facility id is required for getting information about a facility'));
return Promise.reject(new Error('A facility ID is required for getting information about a facility'));
}

@@ -646,8 +660,12 @@

key: 'getAllByOrganizationId',
value: function getAllByOrganizationId(organizationId) {
value: function getAllByOrganizationId(organizationId, options) {
if (!organizationId) {
return Promise.reject(new Error("An organization id is required for getting a list of an organization's facilities"));
return Promise.reject(new Error("An organization ID is required for getting a list of an organization's facilities"));
}
return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/facilities').then(function (facilities) {
var params = formatFacilityOptionsToServer(options);
return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/facilities', {
params: params
}).then(function (facilities) {
return facilities.map(function (facility) {

@@ -663,3 +681,3 @@ return formatFacilityFromServer(facility);

if (!facilityId) {
return Promise.reject(new Error('A facility id is required to update a facility.'));
return Promise.reject(new Error('A facility ID is required to update a facility.'));
}

@@ -666,0 +684,0 @@

{
"name": "@ndustrial/contxt-sdk",
"version": "0.0.10",
"version": "0.0.11",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -5,3 +5,4 @@ import isPlainObject from 'lodash.isplainobject';

formatFacilityFromServer,
formatFacilityToServer
formatFacilityToServer,
formatFacilityOptionsToServer
} from '../utils/facilities';

@@ -21,3 +22,3 @@

* @property {string} [Organization.createdAt] ISO 8601 Extended Format date/time string
* @property {string} [Organization.id] UUID formatted id
* @property {string} [Organization.id] UUID formatted ID
* @property {string} [Organization.name]

@@ -97,3 +98,5 @@ * @property {string} [Organization.updatedAt] ISO 8601 Extended Format date/time string

if (!facility[field]) {
return Promise.reject(new Error(`A ${field} is required to create a new facility.`));
return Promise.reject(
new Error(`A ${field} is required to create a new facility.`)
);
}

@@ -104,4 +107,5 @@ }

return this._request.post(`${this._baseUrl}/facilities`, data)
.then((facility) => formatFacilityFromServer(facility));
return this._request
.post(`${this._baseUrl}/facilities`, data)
.then(facility => formatFacilityFromServer(facility));
}

@@ -115,3 +119,3 @@

*
* @param {number} facilityId The id of the facility to update
* @param {number} facilityId The ID of the facility to update
* @param {Object} update An object containing the facility info for the facility

@@ -130,7 +134,11 @@ *

if (!facilityId) {
return Promise.reject(new Error("A facility id is required to update a facility's info."));
return Promise.reject(
new Error("A facility ID is required to update a facility's info.")
);
}
if (!update) {
return Promise.reject(new Error("An update is required to update a facility's info."));
return Promise.reject(
new Error("An update is required to update a facility's info.")
);
}

@@ -140,3 +148,5 @@

return Promise.reject(
new Error('The facility info update must be a well-formed object with the data you wish to update.')
new Error(
'The facility info update must be a well-formed object with the data you wish to update.'
)
);

@@ -151,3 +161,7 @@ }

return this._request.post(`${this._baseUrl}/facilities/${facilityId}/info`, update, options);
return this._request.post(
`${this._baseUrl}/facilities/${facilityId}/info`,
update,
options
);
}

@@ -161,3 +175,3 @@

*
* @param {number} facilityId The id of the facility
* @param {number} facilityId The ID of the facility
*

@@ -173,3 +187,5 @@ * @returns {Promise}

if (!facilityId) {
return Promise.reject(new Error('A facility id is required for deleting a facility'));
return Promise.reject(
new Error('A facility ID is required for deleting a facility')
);
}

@@ -186,3 +202,3 @@

*
* @param {number} facilityId The id of the facility
* @param {number} facilityId The ID of the facility
*

@@ -201,8 +217,11 @@ * @returns {Promise}

return Promise.reject(
new Error('A facility id is required for getting information about a facility')
new Error(
'A facility ID is required for getting information about a facility'
)
);
}
return this._request.get(`${this._baseUrl}/facilities/${facilityId}`)
.then((facility) => formatFacilityFromServer(facility));
return this._request
.get(`${this._baseUrl}/facilities/${facilityId}`)
.then(facility => formatFacilityFromServer(facility));
}

@@ -226,4 +245,7 @@

getAll() {
return this._request.get(`${this._baseUrl}/facilities`)
.then((facilities) => facilities.map((facility) => formatFacilityFromServer(facility)));
return this._request
.get(`${this._baseUrl}/facilities`)
.then(facilities =>
facilities.map(facility => formatFacilityFromServer(facility))
);
}

@@ -238,2 +260,4 @@

* @param {string} organizationId UUID corresponding with an organization
* @param {object} [options] Object containing parameters to be called with the request
* @param {boolean} [options.includeGroupings] Boolean flag for including groupings data with each facility
*

@@ -245,15 +269,24 @@ * @returns {Promise}

* @example
* contxtSdk.facilities.getAllByOrganizationId(25)
* contxtSdk.facilities.getAllByOrganizationId(25, {includeGroupings: true})
* .then((facilities) => console.log(facilities));
* .catch((err) => console.log(err));
*/
getAllByOrganizationId(organizationId) {
getAllByOrganizationId(organizationId, options) {
if (!organizationId) {
return Promise.reject(
new Error("An organization id is required for getting a list of an organization's facilities")
new Error(
"An organization ID is required for getting a list of an organization's facilities"
)
);
}
return this._request.get(`${this._baseUrl}/organizations/${organizationId}/facilities`)
.then((facilities) => facilities.map((facility) => formatFacilityFromServer(facility)));
const params = formatFacilityOptionsToServer(options);
return this._request
.get(`${this._baseUrl}/organizations/${organizationId}/facilities`, {
params
})
.then(facilities =>
facilities.map(facility => formatFacilityFromServer(facility))
);
}

@@ -267,3 +300,3 @@

*
* @param {number} facilityId The id of the facility to update
* @param {number} facilityId The ID of the facility to update
* @param {Object} update An object containing the updated data for the facility

@@ -295,7 +328,11 @@ * @param {string} [update.address1]

if (!facilityId) {
return Promise.reject(new Error('A facility id is required to update a facility.'));
return Promise.reject(
new Error('A facility ID is required to update a facility.')
);
}
if (!update) {
return Promise.reject(new Error('An update is required to update a facility.'));
return Promise.reject(
new Error('An update is required to update a facility.')
);
}

@@ -305,3 +342,5 @@

return Promise.reject(
new Error('The facility update must be a well-formed object with the data you wish to update.')
new Error(
'The facility update must be a well-formed object with the data you wish to update.'
)
);

@@ -312,3 +351,6 @@ }

return this._request.put(`${this._baseUrl}/facilities/${facilityId}`, formattedUpdate);
return this._request.put(
`${this._baseUrl}/facilities/${facilityId}`,
formattedUpdate
);
}

@@ -315,0 +357,0 @@ }

@@ -5,3 +5,3 @@ import omit from 'lodash.omit';

describe('Facilities', function() {
describe('Facilities', function () {
let baseRequest;

@@ -11,3 +11,3 @@ let baseSdk;

beforeEach(function() {
beforeEach(function () {
this.sandbox = sandbox.create();

@@ -31,22 +31,22 @@

afterEach(function() {
afterEach(function () {
this.sandbox.restore();
});
describe('constructor', function() {
describe('constructor', function () {
let facilities;
beforeEach(function() {
beforeEach(function () {
facilities = new Facilities(baseSdk, baseRequest);
});
it('sets a base url for the class instance', function() {
it('sets a base url for the class instance', function () {
expect(facilities._baseUrl).to.equal(`${baseSdk.config.audiences.facilities.host}/v1`);
});
it('appends the supplied request module to the class instance', function() {
it('appends the supplied request module to the class instance', function () {
expect(facilities._request).to.equal(baseRequest);
});
it('appends the supplied sdk to the class instance', function() {
it('appends the supplied sdk to the class instance', function () {
expect(facilities._sdk).to.equal(baseSdk);

@@ -56,4 +56,4 @@ });

describe('create', function() {
context('when all required information is supplied', function() {
describe('create', function () {
context('when all required information is supplied', function () {
let expectedFacility;

@@ -68,7 +68,13 @@ let formatFacilityFromServer;

beforeEach(function() {
expectedFacility = fixture.build('facility', null, { fromServer: true });
formattedFacility = fixture.build('facility', null, { fromServer: true });
beforeEach(function () {
expectedFacility = fixture.build('facility', null, {
fromServer: true
});
formattedFacility = fixture.build('facility', null, {
fromServer: true
});
initialFacility = fixture.build('facility');
rawFacility = fixture.build('facility', null, { fromServer: true });
rawFacility = fixture.build('facility', null, {
fromServer: true
});

@@ -90,11 +96,11 @@ formatFacilityFromServer = this.sandbox.stub(facilitiesUtils, 'formatFacilityFromServer')

it('formats the submitted facility object to send to the server', function() {
it('formats the submitted facility object to send to the server', function () {
expect(formatFacilityToServer).to.be.calledWith(initialFacility);
});
it('creates a new facility', function() {
it('creates a new facility', function () {
expect(request.post).to.be.deep.calledWith(`${expectedHost}/facilities`, formattedFacility);
});
it('formats the returned facility object', function() {
it('formats the returned facility object', function () {
return promise.then(() => {

@@ -105,3 +111,3 @@ expect(formatFacilityFromServer).to.be.calledWith(rawFacility);

it('returns a fulfilled promise with the new facility information', function() {
it('returns a fulfilled promise with the new facility information', function () {
return expect(promise).to.be.fulfilled

@@ -112,5 +118,5 @@ .and.to.eventually.equal(expectedFacility);

context('when there is missing required information', function() {
['organizationId', 'name', 'timezone'].forEach(function(field) {
it(`it throws an error when ${field} is missing`, function() {
context('when there is missing required information', function () {
['organizationId', 'name', 'timezone'].forEach(function (field) {
it(`it throws an error when ${field} is missing`, function () {
const facility = fixture.build('facility');

@@ -131,4 +137,4 @@ const initialFacility = {

describe('createOrUpdateInfo', function() {
context('when all required information is available', function() {
describe('createOrUpdateInfo', function () {
context('when all required information is available', function () {
let facilityId;

@@ -138,3 +144,3 @@ let facilityInfoUpdate;

beforeEach(function() {
beforeEach(function () {
facilityId = fixture.build('facility').id;

@@ -149,11 +155,14 @@ facilityInfoUpdate = fixture.build('facilityInfo');

it('updates the facility', function() {
it('updates the facility', function () {
expect(baseRequest.post).to.be.calledWith(
`${expectedHost}/facilities/${facilityId}/info`,
facilityInfoUpdate,
{ params: { should_update: true } }
facilityInfoUpdate, {
params: {
should_update: true
}
}
);
});
it('returns a fulfilled promise', function() {
it('returns a fulfilled promise', function () {
return expect(promise).to.be.fulfilled;

@@ -163,10 +172,10 @@ });

context('when there is missing or malformed required information', function() {
context('when there is missing or malformed required information', function () {
let facilities;
beforeEach(function() {
beforeEach(function () {
facilities = new Facilities(baseSdk, baseRequest);
});
it('throws an error when there is no provided facility id', function() {
it('throws an error when there is no provided facility ID', function () {
const facilityInfoUpdate = fixture.build('facilityInfo');

@@ -176,6 +185,6 @@ const promise = facilities.createOrUpdateInfo(null, facilityInfoUpdate);

return expect(promise).to.be
.rejectedWith("A facility id is required to update a facility's info.");
.rejectedWith("A facility ID is required to update a facility's info.");
});
it('throws an error when there is no update provided', function() {
it('throws an error when there is no update provided', function () {
const facility = fixture.build('facility');

@@ -187,3 +196,3 @@ const promise = facilities.createOrUpdateInfo(facility.id);

it('throws an error when the update is not an object', function() {
it('throws an error when the update is not an object', function () {
const facility = fixture.build('facility');

@@ -199,8 +208,8 @@ const promise = facilities.createOrUpdateInfo(facility.id, [facility.info]);

describe('delete', function() {
context('the facility id is provided', function() {
describe('delete', function () {
context('the facility ID is provided', function () {
let facility;
let promise;
beforeEach(function() {
beforeEach(function () {
facility = fixture.build('facility');

@@ -214,3 +223,3 @@

it('requests to delete the facility', function() {
it('requests to delete the facility', function () {
expect(baseRequest.delete).to.be

@@ -220,3 +229,3 @@ .calledWith(`${expectedHost}/facilities/${facility.id}`);

it('returns a resolved promise', function() {
it('returns a resolved promise', function () {
return expect(promise).to.be.fulfilled;

@@ -226,4 +235,4 @@ });

context('the facility id is not provided', function() {
it('throws an error', function() {
context('the facility ID is not provided', function () {
it('throws an error', function () {
const facilities = new Facilities(baseSdk, baseRequest);

@@ -233,3 +242,3 @@ const promise = facilities.delete();

return expect(promise).to.be
.rejectedWith('A facility id is required for deleting a facility');
.rejectedWith('A facility ID is required for deleting a facility');
});

@@ -239,4 +248,4 @@ });

describe('get', function() {
context('the facility id is provided', function() {
describe('get', function () {
context('the facility ID is provided', function () {
let expectedFacilityId;

@@ -249,6 +258,10 @@ let formatFacilityFromServer;

beforeEach(function() {
beforeEach(function () {
expectedFacilityId = faker.random.number();
rawFacility = fixture.build('facility', null, { fromServer: true });
formattedFacility = fixture.build('facility', { id: rawFacility.id });
rawFacility = fixture.build('facility', null, {
fromServer: true
});
formattedFacility = fixture.build('facility', {
id: rawFacility.id
});

@@ -268,7 +281,7 @@ formatFacilityFromServer = this.sandbox.stub(facilitiesUtils, 'formatFacilityFromServer')

it('gets a list of facilities from the server', function() {
it('gets a list of facilities from the server', function () {
expect(request.get).to.be.calledWith(`${expectedHost}/facilities/${expectedFacilityId}`);
});
it('formats the facility object', function() {
it('formats the facility object', function () {
return promise.then(() => {

@@ -279,3 +292,3 @@ expect(formatFacilityFromServer).to.be.calledWith(rawFacility);

it('returns the requested facility', function() {
it('returns the requested facility', function () {
return expect(promise).to.be.fulfilled

@@ -286,4 +299,4 @@ .and.to.eventually.equal(formattedFacility);

context('the facility id is not provided', function() {
it('throws an error', function() {
context('the facility ID is not provided', function () {
it('throws an error', function () {
const facilities = new Facilities(baseSdk, baseRequest);

@@ -293,3 +306,3 @@ const promise = facilities.get();

return expect(promise).to.be
.rejectedWith('A facility id is required for getting information about a facility');
.rejectedWith('A facility ID is required for getting information about a facility');
});

@@ -299,3 +312,3 @@ });

describe('getAll', function() {
describe('getAll', function () {
let formatFacilityFromServer;

@@ -307,6 +320,11 @@ let formattedFacilities;

beforeEach(function() {
const numberOfFacilities = faker.random.number({ min: 1, max: 10 });
beforeEach(function () {
const numberOfFacilities = faker.random.number({
min: 1,
max: 10
});
formattedFacilities = fixture.buildList('facility', numberOfFacilities);
rawFacilities = fixture.buildList('facility', numberOfFacilities, null, { fromServer: true });
rawFacilities = fixture.buildList('facility', numberOfFacilities, null, {
fromServer: true
});

@@ -329,7 +347,7 @@ formatFacilityFromServer = this.sandbox.stub(facilitiesUtils, 'formatFacilityFromServer')

it('gets a list of facilities from the server', function() {
it('gets a list of facilities from the server', function () {
expect(request.get).to.be.calledWith(`${expectedHost}/facilities`);
});
it('formats the facility object', function() {
it('formats the facility object', function () {
return promise.then(() => {

@@ -344,3 +362,3 @@ expect(formatFacilityFromServer).to.have.callCount(rawFacilities.length);

it('returns a list of facilities', function() {
it('returns a list of facilities', function () {
return expect(promise).to.be.fulfilled

@@ -351,17 +369,29 @@ .and.to.eventually.deep.equal(formattedFacilities);

describe('getAllByOrganizationId', function() {
context('the organization id is not provided', function() {
describe('getAllByOrganizationId', function () {
context('the organization ID is provided', function () {
let expectedOrganizationId;
let formatFacilityFromServer;
let formatFacilityOptionsToServer;
let formattedFacilities;
let initialOptions;
let promise;
let rawFacilities;
let rawFacilityOptions;
let request;
beforeEach(function() {
beforeEach(function () {
expectedOrganizationId = faker.random.number();
const numberOfFacilities = faker.random.number({ min: 1, max: 10 });
const numberOfFacilities = faker.random.number({
min: 1,
max: 10
});
formattedFacilities = fixture.buildList('facility', numberOfFacilities);
rawFacilities = fixture.buildList('facility', numberOfFacilities, null, { fromServer: true });
rawFacilities = fixture.buildList('facility', numberOfFacilities, null, {
fromServer: true
});
initialOptions = faker.helpers.createTransaction();
rawFacilityOptions = faker.helpers.createTransaction();
formatFacilityOptionsToServer = this.sandbox.stub(facilitiesUtils, 'formatFacilityOptionsToServer')
.returns(rawFacilityOptions);
formatFacilityFromServer = this.sandbox.stub(facilitiesUtils, 'formatFacilityFromServer')

@@ -380,12 +410,18 @@ .callsFake((facility) => {

promise = facilities.getAllByOrganizationId(expectedOrganizationId);
promise = facilities.getAllByOrganizationId(expectedOrganizationId, initialOptions);
});
it('gets a list of facilities for an organization from the server', function() {
it('gets options that are in a format suitable for the API', function () {
expect(formatFacilityOptionsToServer).to.be.calledWith(initialOptions);
});
it('gets a list of facilities for an organization from the server', function () {
expect(request.get).to.be.calledWith(
`${expectedHost}/organizations/${expectedOrganizationId}/facilities`
`${expectedHost}/organizations/${expectedOrganizationId}/facilities`, {
params: rawFacilityOptions
}
);
});
it('formats the facility object', function() {
it('formats the facility object', function () {
return promise.then(() => {

@@ -400,3 +436,3 @@ expect(formatFacilityFromServer).to.have.callCount(rawFacilities.length);

it('returns a list of facilities', function() {
it('returns a list of facilities', function () {
return expect(promise).to.be.fulfilled

@@ -407,4 +443,4 @@ .and.to.eventually.deep.equal(formattedFacilities);

context('the organization id is not provided', function() {
it('throws an error', function() {
context('the organization id is not provided', function () {
it('throws an error', function () {
const facilities = new Facilities(baseSdk, baseRequest);

@@ -414,3 +450,3 @@ const promise = facilities.getAllByOrganizationId();

return expect(promise).to.be.rejectedWith(
"An organization id is required for getting a list of an organization's facilities"
"An organization ID is required for getting a list of an organization's facilities"
);

@@ -421,4 +457,4 @@ });

describe('update', function() {
context('when all required information is available', function() {
describe('update', function () {
context('when all required information is available', function () {
let facilityUpdate;

@@ -429,5 +465,7 @@ let formatFacilityToServer;

beforeEach(function() {
beforeEach(function () {
facilityUpdate = fixture.build('facility');
formattedFacility = fixture.build('facility', null, { fromServer: true });
formattedFacility = fixture.build('facility', null, {
fromServer: true
});

@@ -443,7 +481,7 @@ formatFacilityToServer = this.sandbox.stub(facilitiesUtils, 'formatFacilityToServer')

it('formats the data into the right format', function() {
it('formats the data into the right format', function () {
expect(formatFacilityToServer).to.be.calledWith(facilityUpdate);
});
it('updates the facility', function() {
it('updates the facility', function () {
expect(baseRequest.put).to.be.calledWith(

@@ -455,3 +493,3 @@ `${expectedHost}/facilities/${facilityUpdate.id}`,

it('returns a fulfilled promise', function() {
it('returns a fulfilled promise', function () {
return expect(promise).to.be.fulfilled;

@@ -461,10 +499,10 @@ });

context('when there is missing or malformed required information', function() {
context('when there is missing or malformed required information', function () {
let facilities;
beforeEach(function() {
beforeEach(function () {
facilities = new Facilities(baseSdk, baseRequest);
});
it('throws an error when there is no provided facility id', function() {
it('throws an error when there is no provided facility id', function () {
const facilityUpdate = fixture.build('facility');

@@ -474,6 +512,6 @@ const promise = facilities.update(null, facilityUpdate);

return expect(promise).to.be
.rejectedWith('A facility id is required to update a facility.');
.rejectedWith('A facility ID is required to update a facility.');
});
it('throws an error when there is no update provided', function() {
it('throws an error when there is no update provided', function () {
const facilityUpdate = fixture.build('facility');

@@ -485,3 +523,3 @@ const promise = facilities.update(facilityUpdate.id);

it('throws an error when the update is not an object', function() {
it('throws an error when the update is not an object', function () {
const facilityUpdate = fixture.build('facility');

@@ -488,0 +526,0 @@ const promise = facilities.update(facilityUpdate.id, [facilityUpdate]);

import {
formatOrganizationFromServer,
formatTagsFromServer
formatTagsFromServer,
formatGroupingFromServer
} from './index';

@@ -14,2 +15,8 @@

* @param {string} input.created_at ISO 8601 Extended Format date/time string
* @param {Object[]}[input.facility_groupings]
* @param {string} [input.facility_groupings[].created_at] ISO 8601 Extended Format date/time string
* @param {number} [input.facility_groupings[].facility_id] ID corresponding with the parent facility
* @param {number} [input.facility_groupings[].id]
* @param {string} [input.facility_groupings[].name]
* @param {string} [input.facility_groupings[].updated_at] ISO 8601 Extended Format date/time string
* @param {string} input.geometry_id UUID corresponding with a geometry

@@ -28,3 +35,3 @@ * @param {number} input.id

* @param {string} [input.tags[].created_at] ISO 8601 Extended Format date/time string
* @param {number} [input.tags[].facility_id] Id corresponding with the parent facility
* @param {number} [input.tags[].facility_id] ID corresponding with the parent facility
* @param {number} [input.tags[].id]

@@ -69,2 +76,6 @@ * @param {string} [input.tags[].name]

if (input.facility_groupings) {
facility.facility_groupings = input.facility_groupings.map(formatGroupingFromServer);
}
return facility;

@@ -71,0 +82,0 @@ }

@@ -5,7 +5,8 @@ import omit from 'lodash.omit';

describe('utils/facilities/formatFacilityFromServer', function() {
describe('utils/facilities/formatFacilityFromServer', function () {
let formatOrganizationFromServer;
let formatTagsFromServer;
let formatGroupingFromServer;
beforeEach(function() {
beforeEach(function () {
this.sandbox = sandbox.create();

@@ -17,9 +18,11 @@

.callsFake((tags) => tags);
formatGroupingFromServer = this.sandbox.stub(facilitiesUtils, 'formatGroupingFromServer')
.callsFake((grouping) => grouping);
});
afterEach(function() {
afterEach(function () {
this.sandbox.restore();
});
context('when all possible fields are in the facility object', function() {
context('when all possible fields are in the facility object', function () {
let expectedFacility;

@@ -29,23 +32,22 @@ let facility;

beforeEach(function() {
facility = fixture.build('facility', null, { fromServer: true });
expectedFacility = omit(
{
...facility,
createdAt: facility.created_at,
geometryId: facility.geometry_id,
info: facility.Info,
organization: facility.Organization,
organizationId: facility.organization_id,
weatherLocationId: facility.weather_location_id
},
[
'created_at',
'geometry_id',
'Info',
'Organization',
'organization_id',
'weather_location_id'
]
);
beforeEach(function () {
facility = fixture.build('facility', null, {
fromServer: true
});
expectedFacility = omit({
...facility,
createdAt: facility.created_at,
geometryId: facility.geometry_id,
info: facility.Info,
organization: facility.Organization,
organizationId: facility.organization_id,
weatherLocationId: facility.weather_location_id
}, [
'created_at',
'geometry_id',
'Info',
'Organization',
'organization_id',
'weather_location_id'
]);

@@ -55,8 +57,11 @@ formattedFacility = formatFacilityFromServer(facility);

it('formats the necessary children objects', function() {
it('formats the necessary children objects', function () {
expect(formatOrganizationFromServer).to.be.calledWith(facility.Organization);
expect(formatTagsFromServer).to.be.calledWith(facility.tags);
facility.facility_groupings.forEach((grouping) =>
expect(formatGroupingFromServer).to.be.calledWith(grouping)
);
});
it('converts the object keys to the camelCase', function() {
it('converts the object keys to the camelCase', function () {
expect(formattedFacility).to.deep.equal(expectedFacility);

@@ -66,5 +71,7 @@ });

context('when the facilities object does not have all possible keys', function() {
it('does not include the facility info if facility info is in the initial data', function() {
const facility = fixture.build('facility', null, { fromServer: true });
context('when the facilities object does not have all possible keys', function () {
it('does not include the facility info if facility info is in the initial data', function () {
const facility = fixture.build('facility', null, {
fromServer: true
});
delete facility.Info;

@@ -76,4 +83,6 @@ const formattedFacility = formatFacilityFromServer(facility);

it('does not include the organization if organization info is not in the initial data', function() {
const facility = fixture.build('facility', null, { fromServer: true });
it('does not include the organization if organization info is not in the initial data', function () {
const facility = fixture.build('facility', null, {
fromServer: true
});
delete facility.Organization;

@@ -86,4 +95,6 @@ const formattedFacility = formatFacilityFromServer(facility);

it('does not include the tags if tags are not in the initial data', function() {
const facility = fixture.build('facility', null, { fromServer: true });
it('does not include the tags if tags are not in the initial data', function () {
const facility = fixture.build('facility', null, {
fromServer: true
});
delete facility.tags;

@@ -95,3 +106,14 @@ const formattedFacility = formatFacilityFromServer(facility);

});
it('does not include the facilities groupings if groupings are not in the initial data', function () {
const facility = fixture.build('facility', null, {
fromServer: true
});
delete facility.facility_groupings;
const formattedFacility = formatFacilityFromServer(facility);
expect(formatGroupingFromServer).to.be.not.called;
expect(formattedFacility).to.not.include.keys(['facility_groupings']);
});
});
});
import omit from 'lodash.omit';
import formatFacilityToServer from './formatFacilityToServer';
describe('utils/facilities/formatFacilityToServer', function() {
describe('utils/facilities/formatFacilityToServer', function () {
let expectedFacility;

@@ -9,23 +9,21 @@ let facility;

beforeEach(function() {
beforeEach(function () {
facility = fixture.build('facility');
expectedFacility = omit(
{
...facility,
geometry_id: facility.geometryId,
Info: facility.info,
organization_id: facility.organizationId,
weather_location_id: facility.weatherLocationId
},
[
'createdAt',
'geometryId',
'id',
'info',
'organization',
'organizationId',
'tags',
'weatherLocationId'
]
);
expectedFacility = omit({
...facility,
geometry_id: facility.geometryId,
Info: facility.info,
organization_id: facility.organizationId,
weather_location_id: facility.weatherLocationId
}, [
'createdAt',
'facility_groupings',
'geometryId',
'id',
'info',
'organization',
'organizationId',
'tags',
'weatherLocationId'
]);

@@ -35,5 +33,5 @@ formattedFacility = formatFacilityToServer(facility);

it('converts the object keys to snake case and capitalizes certain keys', function() {
it('converts the object keys to snake case and capitalizes certain keys', function () {
expect(formattedFacility).to.deep.equal(expectedFacility);
});
});

@@ -6,9 +6,9 @@ /**

*
* @param {Object} output
* @param {string} output.description
* @param {boolean} output.is_private
* @param {string} output.name
* @param {string} output.organization_id UUID
* @param {string} output.owner_id Auth0 identifer of the owner
* @param {string} output.parent_grouping_id UUID
* @returns {Object} output
* @returns {string} output.description
* @returns {boolean} output.is_private
* @returns {string} output.name
* @returns {string} output.organization_id UUID
* @returns {string} output.owner_id Auth0 identifer of the owner
* @returns {string} output.parent_grouping_id UUID
*

@@ -15,0 +15,0 @@ * @private

import formatFacilityFromServer from './formatFacilityFromServer';
import formatFacilityToServer from './formatFacilityToServer';
import formatFacilityOptionsToServer from './formatFacilityOptionsToServer';
import formatGroupingFacilityFromServer from './formatGroupingFacilityFromServer';

@@ -12,2 +13,3 @@ import formatGroupingFromServer from './formatGroupingFromServer';

formatFacilityToServer,
formatFacilityOptionsToServer,
formatGroupingFacilityFromServer,

@@ -14,0 +16,0 @@ formatGroupingFromServer,

@@ -29,10 +29,31 @@ 'use strict';

})
.attr('facility_groupings', ['id', 'fromServer'], (id, fromServer) => {
return times(faker.random.number({
min: 0,
max: 5
}), () => {
return factory.build('facilityGrouping', {
facilityId: id
}, {
fromServer
});
});
})
.attr('name', ['city'], (city) => `${faker.address.cityPrefix()} ${city}`)
.attr('organization', ['fromServer'], (fromServer) => {
return factory.build('organization', null, { fromServer });
return factory.build('organization', null, {
fromServer
});
})
.attr('organizationId', ['organization'], (organization) => organization.id)
.attr('tags', ['id', 'fromServer'], (id, fromServer) => {
return times(faker.random.number({ min: 0, max: 5 }), () => {
return factory.build('facilityTag', { facilityId: id }, { fromServer });
return times(faker.random.number({
min: 0,
max: 5
}), () => {
return factory.build('facilityTag', {
facilityId: id
}, {
fromServer
});
});

@@ -39,0 +60,0 @@ })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc