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

@ndustrial/contxt-sdk

Package Overview
Dependencies
Maintainers
7
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.9 to 0.0.10

60

CHANGELOG.md

@@ -1,47 +0,69 @@

## [v0.0.8](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.9) (2018-04-19)
## [v0.0.10](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.10) (2018-05-01)
**Added**
- FacilityGroupings#getAllByOrganizationId for getting all facility groupings for a specific organization
* FacilityGroupings#remove to remove an existing facility grouping
* FacilityGroupings#update to update an existing facility grouping
## [v0.0.9](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.9) (2018-04-19)
**Added**
* FacilityGroupings#getAllByOrganizationId for getting all facility groupings for a specific organization
## [v0.0.8](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.8) (2018-04-16)
**Added**
- Added some methods to help out when working with facility groupings. They are namespaced under facilities (i.e. `facilities.groupings.methodName()`) and include:
- FacilityGroupings#addFacility to add a facility to a facility grouping
- FacilityGroupings#create for creating new facility groupings
- FacilityGroupings#getAll for getting a list of all facility groupings
- FacilityGroupings#removeFacility to remove a facility from a facility grouping
* Added some methods to help out when working with facility groupings. They are namespaced under facilities (i.e. `facilities.groupings.methodName()`) and include:
* FacilityGroupings#addFacility to add a facility to a facility grouping
* FacilityGroupings#create for creating new facility groupings
* FacilityGroupings#getAll for getting a list of all facility groupings
* FacilityGroupings#removeFacility to remove a facility from a facility grouping
## [v0.0.7](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.7) (2018-03-29)
**Renamed**
- Facilities#updateInfo to Facilities#createOrUpdateInfo so that what the method does is more obvious
* Facilities#updateInfo to Facilities#createOrUpdateInfo so that what the method does is more obvious
## [v0.0.6](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.6) (2018-03-28)
**Added**
- Facilities#updateInfo for updating a facility's facilily info
* Facilities#updateInfo for updating a facility's facilily info
## [v0.0.5](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.5) (2018-03-20)
**Added**
- Facilities#create, Facilities#delete, Facilities#getAllByOrganizationId, and Facilities#update
* Facilities#create, Facilities#delete, Facilities#getAllByOrganizationId, and Facilities#update
## [v0.0.4](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.4) (2018-03-08)
**Added**
- MachineAuth SessionType for use on Node.js projects
* MachineAuth SessionType for use on Node.js projects
**Changed**
- Split API documentation into multiple files for easy reading and navigation
* Split API documentation into multiple files for easy reading and navigation
**Fixed**
- Updated required version of `auth0-js` to fix [CVS-2018-7307](https://auth0.com/docs/security/bulletins/cve-2018-7307)
* Updated required version of `auth0-js` to fix [CVS-2018-7307](https://auth0.com/docs/security/bulletins/cve-2018-7307)
## v0.0.3 (2018-02-26)
- Adds documentation!
- Fixes bug where placement of customModuleConfigs and the chosen environment in the user config did not match up with what was in documentation
* Adds documentation!
* Fixes bug where placement of customModuleConfigs and the chosen environment in the user config did not match up with what was in documentation
## v0.0.2 (2018-02-26)
- Fixes publication process so that the built files are in the package grabbed from NPM
* Fixes publication process so that the built files are in the package grabbed from NPM
## v0.0.1 (2018-02-23)
- Initial release
- Provides Request, Config and an initial SessionType, Auth0WebAuth
- Provides Facilities#get and Facilities#getAll
* Initial release
* Provides Request, Config and an initial SessionType, Auth0WebAuth
* Provides Facilities#get and Facilities#getAll

@@ -13,5 +13,7 @@ <a name="FacilityGroupings"></a>

* [.create(facilityGrouping)](#FacilityGroupings+create) ⇒ <code>Promise</code>
* [.delete(facilityGroupingId)](#FacilityGroupings+delete) ⇒ <code>Promise</code>
* [.getAll()](#FacilityGroupings+getAll) ⇒ <code>Promise</code>
* [.getAllByOrganizationId(organizationId)](#FacilityGroupings+getAllByOrganizationId) ⇒ <code>Promise</code>
* [.removeFacility(facilityGroupingId, facilityId)](#FacilityGroupings+removeFacility) ⇒ <code>Promise</code>
* [.update(facilityGroupingId, update)](#FacilityGroupings+update) ⇒ <code>Promise</code>

@@ -85,2 +87,22 @@ <a name="new_FacilityGroupings_new"></a>

```
<a name="FacilityGroupings+delete"></a>
### contxtSdk.facilities.groupings.delete(facilityGroupingId) ⇒ <code>Promise</code>
Delete a facility groupings
API Endpoint: '/groupings/:facilityGroupingId'
Method: DELETE
**Kind**: instance method of [<code>FacilityGroupings</code>](#FacilityGroupings)
**Fulfill**: <code>undefined</code>
**Reject**: <code>Error</code>
| Param | Type | Description |
| --- | --- | --- |
| facilityGroupingId | <code>string</code> | The id of the facility grouping (formatted as a UUID) |
**Example**
```js
contxtSdk.facilities.groupings.delete('e4fec739-56aa-4b50-8dab-e9d6b9c91a5d')
```
<a name="FacilityGroupings+getAll"></a>

@@ -148,1 +170,34 @@

```
<a name="FacilityGroupings+update"></a>
### contxtSdk.facilities.groupings.update(facilityGroupingId, update) ⇒ <code>Promise</code>
Updates an existing facility grouping
API Endpoint: '/groupings/:facilityGroupingId'
Method: PUT
**Kind**: instance method of [<code>FacilityGroupings</code>](#FacilityGroupings)
**Fulfill**: [<code>FacilityGrouping</code>](./Typedefs.md#FacilityGrouping) Information about the updated facility grouping
**Reject**: <code>Error</code>
| Param | Type | Description |
| --- | --- | --- |
| facilityGroupingId | <code>String</code> | |
| update | <code>Object</code> | |
| [update.description] | <code>string</code> | |
| [update.isPrivate] | <code>boolean</code> | |
| [update.name] | <code>string</code> | |
| [update.parentGroupingId] | <code>string</code> | UUID corresponding with another facility grouping |
**Example**
```js
contxtSdk.facilities.groupings
.update({
description: 'US States of CT, MA, ME, NH, RI, VT',
isPrivate: false,
name: 'New England, USA',
parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e'
})
.then((grouping) => console.log(grouping))
.catch((err) => console.log(err));
```

@@ -471,2 +471,12 @@ import axios from 'axios';

}, {
key: 'delete',
value: function _delete(facilityGroupingId) {
if (!facilityGroupingId) {
return Promise.reject(new Error('A facility grouping id is required for deleting a facility grouping.'));
}
return this._request.delete(this._baseUrl + '/groupings/' + facilityGroupingId);
}
}, {
key: 'getAll',

@@ -508,2 +518,24 @@ value: function getAll() {

}
}, {
key: 'update',
value: function update(facilityGroupingId, _update) {
if (!facilityGroupingId) {
return Promise.reject(new Error('A facility grouping id is required to update a facility grouping.'));
}
if (!_update) {
return Promise.reject(new Error('An update is required to update a facility grouping'));
}
if (!lodash_isplainobject(_update)) {
return Promise.reject(new Error('The facility grouping update must be a well-formed object with the data you wish to update.'));
}
var formattedUpdate = formatGroupingToServer(_update);
return this._request.put(this._baseUrl + '/groupings/' + facilityGroupingId, formattedUpdate).then(function (grouping) {
return formatGroupingFromServer(grouping);
});
}
}]);

@@ -510,0 +542,0 @@ return FacilityGroupings;

@@ -475,2 +475,12 @@ 'use strict';

}, {
key: 'delete',
value: function _delete(facilityGroupingId) {
if (!facilityGroupingId) {
return Promise.reject(new Error('A facility grouping id is required for deleting a facility grouping.'));
}
return this._request.delete(this._baseUrl + '/groupings/' + facilityGroupingId);
}
}, {
key: 'getAll',

@@ -512,2 +522,24 @@ value: function getAll() {

}
}, {
key: 'update',
value: function update(facilityGroupingId, _update) {
if (!facilityGroupingId) {
return Promise.reject(new Error('A facility grouping id is required to update a facility grouping.'));
}
if (!_update) {
return Promise.reject(new Error('An update is required to update a facility grouping'));
}
if (!lodash_isplainobject(_update)) {
return Promise.reject(new Error('The facility grouping update must be a well-formed object with the data you wish to update.'));
}
var formattedUpdate = formatGroupingToServer(_update);
return this._request.put(this._baseUrl + '/groupings/' + facilityGroupingId, formattedUpdate).then(function (grouping) {
return formatGroupingFromServer(grouping);
});
}
}]);

@@ -514,0 +546,0 @@ return FacilityGroupings;

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

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

@@ -0,1 +1,2 @@

import isPlainObject from 'lodash.isplainobject';
import {

@@ -70,5 +71,7 @@ formatGroupingFacilityFromServer,

if (!facilityGroupingId) {
errorMsg = 'A facilityGroupingId is required to create a relationship between a facility grouping and a facility.';
errorMsg =
'A facilityGroupingId is required to create a relationship between a facility grouping and a facility.';
} else if (!facilityId) {
errorMsg = 'A facilityId is required to create a relationship between a facility grouping and a facility.';
errorMsg =
'A facilityId is required to create a relationship between a facility grouping and a facility.';
}

@@ -80,4 +83,11 @@

return this._request.post(`${this._baseUrl}/groupings/${facilityGroupingId}/facility/${facilityId}`)
.then((groupingFacility) => formatGroupingFacilityFromServer(groupingFacility));
return this._request
.post(
`${
this._baseUrl
}/groupings/${facilityGroupingId}/facility/${facilityId}`
)
.then(groupingFacility =>
formatGroupingFacilityFromServer(groupingFacility)
);
}

@@ -129,7 +139,37 @@

return this._request.post(`${this._baseUrl}/groupings`, data)
.then((grouping) => formatGroupingFromServer(grouping));
return this._request
.post(`${this._baseUrl}/groupings`, data)
.then(grouping => formatGroupingFromServer(grouping));
}
/**
* Delete a facility groupings
*
* API Endpoint: '/groupings/:facilityGroupingId'
* Method: DELETE
*
* @param {string} facilityGroupingId The id of the facility grouping (formatted as a UUID)
*
* @returns {Promise}
* @fulfill {undefined}
* @reject {Error}
*
* @example
* contxtSdk.facilities.groupings.delete('e4fec739-56aa-4b50-8dab-e9d6b9c91a5d')
*/
delete(facilityGroupingId) {
if (!facilityGroupingId) {
return Promise.reject(
new Error(
'A facility grouping id is required for deleting a facility grouping.'
)
);
}
return this._request.delete(
`${this._baseUrl}/groupings/${facilityGroupingId}`
);
}
/**
* Get a listing of all facility groupings available to a user. Includes public groupings across

@@ -151,4 +191,5 @@ * any organization the user has access to and the user's private groupings.

getAll() {
return this._request.get(`${this._baseUrl}/groupings`)
.then((groupings) => groupings.map(formatGroupingFromServer));
return this._request
.get(`${this._baseUrl}/groupings`)
.then(groupings => groupings.map(formatGroupingFromServer));
}

@@ -177,8 +218,11 @@

return Promise.reject(
new Error("An organization id is required for getting a list of an organization's facility groupings")
new Error(
"An organization id is required for getting a list of an organization's facility groupings"
)
);
}
return this._request.get(`${this._baseUrl}/organizations/${organizationId}/groupings`)
.then((groupings) => groupings.map(formatGroupingFromServer));
return this._request
.get(`${this._baseUrl}/organizations/${organizationId}/groupings`)
.then(groupings => groupings.map(formatGroupingFromServer));
}

@@ -206,5 +250,7 @@

if (!facilityGroupingId) {
errorMsg = 'A facilityGroupingId is required to remove a relationship between a facility grouping and a facility.';
errorMsg =
'A facilityGroupingId is required to remove a relationship between a facility grouping and a facility.';
} else if (!facilityId) {
errorMsg = 'A facilityId is required to remove a relationship between a facility grouping and a facility.';
errorMsg =
'A facilityId is required to remove a relationship between a facility grouping and a facility.';
}

@@ -220,4 +266,62 @@

}
/**
* Updates an existing facility grouping
*
* API Endpoint: '/groupings/:facilityGroupingId'
* Method: PUT
*
* @param {String} facilityGroupingId
* @param {Object} update
* @param {string} [update.description]
* @param {boolean} [update.isPrivate]
* @param {string} [update.name]
* @param {string} [update.parentGroupingId] UUID corresponding with another facility grouping
*
* @returns {Promise}
* @fulfill {FacilityGrouping} Information about the updated facility grouping
* @reject {Error}
*
* @example
* contxtSdk.facilities.groupings
* .update({
* description: 'US States of CT, MA, ME, NH, RI, VT',
* isPrivate: false,
* name: 'New England, USA',
* parentGroupingId: 'e9f8f89c-609c-4c83-8ebc-cea928af661e'
* })
* .then((grouping) => console.log(grouping))
* .catch((err) => console.log(err));
*/
update(facilityGroupingId, update) {
if (!facilityGroupingId) {
return Promise.reject(
new Error(
'A facility grouping id is required to update a facility grouping.'
)
);
}
if (!update) {
return Promise.reject(
new Error('An update is required to update a facility grouping')
);
}
if (!isPlainObject(update)) {
return Promise.reject(
new Error(
'The facility grouping update must be a well-formed object with the data you wish to update.'
)
);
}
const formattedUpdate = formatGroupingToServer(update);
return this._request
.put(`${this._baseUrl}/groupings/${facilityGroupingId}`, formattedUpdate)
.then(grouping => formatGroupingFromServer(grouping));
}
}
export default FacilityGroupings;

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

get: this.sandbox.stub().resolves(),
post: this.sandbox.stub().resolves()
post: this.sandbox.stub().resolves(),
put: this.sandbox.stub().resolves()
};

@@ -37,3 +38,7 @@ baseSdk = {

beforeEach(function() {
facilityGroupings = new FacilityGroupings(baseSdk, baseRequest, expectedHost);
facilityGroupings = new FacilityGroupings(
baseSdk,
baseRequest,
expectedHost
);
});

@@ -68,5 +73,8 @@

expectedGroupingId = expectedGroupingFacility.facilityGroupingId;
rawGroupingFacility = fixture.build('facilityGroupingFacility', { fromServer: true });
rawGroupingFacility = fixture.build('facilityGroupingFacility', {
fromServer: true
});
formatGroupingFacilityFromServer = this.sandbox.stub(facilitiesUtils, 'formatGroupingFacilityFromServer')
formatGroupingFacilityFromServer = this.sandbox
.stub(facilitiesUtils, 'formatGroupingFacilityFromServer')
.returns(expectedGroupingFacility);

@@ -78,5 +86,12 @@ request = {

const facilityGroupings = new FacilityGroupings(baseSdk, request, expectedHost);
const facilityGroupings = new FacilityGroupings(
baseSdk,
request,
expectedHost
);
promise = facilityGroupings.addFacility(expectedGroupingId, expectedFacilityId);
promise = facilityGroupings.addFacility(
expectedGroupingId,
expectedFacilityId
);
});

@@ -92,3 +107,5 @@

return promise.then(() => {
expect(formatGroupingFacilityFromServer).to.be.calledWith(rawGroupingFacility);
expect(formatGroupingFacilityFromServer).to.be.calledWith(
rawGroupingFacility
);
});

@@ -98,4 +115,5 @@ });

it('returns a fulfilled promise with the new facility information', function() {
return expect(promise).to.be.fulfilled
.and.to.eventually.equal(expectedGroupingFacility);
return expect(promise).to.be.fulfilled.and.to.eventually.equal(
expectedGroupingFacility
);
});

@@ -110,3 +128,7 @@ });

const facilityGroupings = new FacilityGroupings(baseSdk, baseRequest, expectedHost);
const facilityGroupings = new FacilityGroupings(
baseSdk,
baseRequest,
expectedHost
);
const promise = facilityGroupings.addFacility(

@@ -117,4 +139,5 @@ groupingFacility.facilityGroupingId,

return expect(promise).to.be
.rejectedWith(`A ${field} is required to create a relationship between a facility grouping and a facility.`);
return expect(promise).to.be.rejectedWith(
`A ${field} is required to create a relationship between a facility grouping and a facility.`
);
});

@@ -138,9 +161,17 @@ });

initialGrouping = fixture.build('facilityGrouping');
formattedGroupingToServer = fixture.build('facilityGrouping', null, { fromServer: true });
formattedGroupingFromServer = fixture.build('facilityGrouping', null, { fromServer: true });
expectedGrouping = fixture.build('facilityGrouping', null, { fromServer: true });
formattedGroupingToServer = fixture.build('facilityGrouping', null, {
fromServer: true
});
formattedGroupingFromServer = fixture.build('facilityGrouping', null, {
fromServer: true
});
expectedGrouping = fixture.build('facilityGrouping', null, {
fromServer: true
});
formatGroupingFromServer = this.sandbox.stub(facilitiesUtils, 'formatGroupingFromServer')
formatGroupingFromServer = this.sandbox
.stub(facilitiesUtils, 'formatGroupingFromServer')
.returns(expectedGrouping);
formatGroupingToServer = this.sandbox.stub(facilitiesUtils, 'formatGroupingToServer')
formatGroupingToServer = this.sandbox
.stub(facilitiesUtils, 'formatGroupingToServer')
.returns(formattedGroupingToServer);

@@ -152,3 +183,7 @@ request = {

const facilityGroupings = new FacilityGroupings(baseSdk, request, expectedHost);
const facilityGroupings = new FacilityGroupings(
baseSdk,
request,
expectedHost
);

@@ -163,4 +198,6 @@ promise = facilityGroupings.create(initialGrouping);

it('creates a new facility grouping', function() {
expect(request.post)
.to.be.deep.calledWith(`${expectedHost}/groupings`, formattedGroupingToServer);
expect(request.post).to.be.deep.calledWith(
`${expectedHost}/groupings`,
formattedGroupingToServer
);
});

@@ -170,3 +207,5 @@

return promise.then(() => {
expect(formatGroupingFromServer).to.be.calledWith(formattedGroupingFromServer);
expect(formatGroupingFromServer).to.be.calledWith(
formattedGroupingFromServer
);
});

@@ -176,4 +215,5 @@ });

it('returns a fulfilled promise with the new facility grouping information', function() {
return expect(promise).to.be.fulfilled
.and.to.eventually.equal(expectedGrouping);
return expect(promise).to.be.fulfilled.and.to.eventually.equal(
expectedGrouping
);
});

@@ -186,7 +226,14 @@ });

const facilityGrouping = fixture.build('facilityGrouping');
const facilityGroupings = new FacilityGroupings(baseSdk, baseRequest, expectedHost);
const promise = facilityGroupings.create(omit(facilityGrouping, [field]));
const facilityGroupings = new FacilityGroupings(
baseSdk,
baseRequest,
expectedHost
);
const promise = facilityGroupings.create(
omit(facilityGrouping, [field])
);
return expect(promise).to.be
.rejectedWith(`A ${field} is required to create a new facility grouping.`);
return expect(promise).to.be.rejectedWith(
`A ${field} is required to create a new facility grouping.`
);
});

@@ -197,2 +244,45 @@ });

describe('delete', function() {
context('when all required information is supplied', function() {
let expectedFacilityGroupingId;
let promise;
beforeEach(function() {
expectedFacilityGroupingId = fixture.build('facilityGrouping').id;
const facilityGroupings = new FacilityGroupings(
baseSdk,
baseRequest,
expectedHost
);
promise = facilityGroupings.delete(expectedFacilityGroupingId);
});
it('requests to delete the facility grouping', function() {
expect(baseRequest.delete).to.be.calledWith(
`${expectedHost}/groupings/${expectedFacilityGroupingId}`
);
});
it('returns a fulfilled promise', function() {
return expect(promise).to.be.fulfilled;
});
});
context('when there is missing required information', function() {
it(`it throws an error when the facility grouping id is missing`, function() {
const expectedErrorMessage = `A facility grouping id is required for deleting a facility grouping.`;
const facilityGroupings = new FacilityGroupings(
baseSdk,
baseRequest,
expectedHost
);
const promise = facilityGroupings.delete();
return expect(promise).to.be.rejectedWith(expectedErrorMessage);
});
});
});
describe('getAll', function() {

@@ -207,6 +297,13 @@ let expectedGrouping;

const numberOfGroupings = faker.random.number({ min: 1, max: 10 });
expectedGrouping = fixture.buildList('facilityGrouping', numberOfGroupings);
groupingsFromServer = fixture.buildList('facilityGrouping', numberOfGroupings);
expectedGrouping = fixture.buildList(
'facilityGrouping',
numberOfGroupings
);
groupingsFromServer = fixture.buildList(
'facilityGrouping',
numberOfGroupings
);
formatGroupingFromServer = this.sandbox.stub(facilitiesUtils, 'formatGroupingFromServer')
formatGroupingFromServer = this.sandbox
.stub(facilitiesUtils, 'formatGroupingFromServer')
.callsFake((grouping, index) => expectedGrouping[index]);

@@ -218,3 +315,7 @@ request = {

const facilityGroupings = new FacilityGroupings(baseSdk, request, expectedHost);
const facilityGroupings = new FacilityGroupings(
baseSdk,
request,
expectedHost
);
promise = facilityGroupings.getAll();

@@ -229,4 +330,6 @@ });

return promise.then(() => {
expect(formatGroupingFromServer).to.have.callCount(groupingsFromServer.length);
groupingsFromServer.forEach((grouping) => {
expect(formatGroupingFromServer).to.have.callCount(
groupingsFromServer.length
);
groupingsFromServer.forEach(grouping => {
expect(formatGroupingFromServer).to.be.calledWith(grouping);

@@ -238,4 +341,5 @@ });

it('returns a fulfilled promise with the facility groupings', function() {
return expect(promise).to.be.fulfilled
.and.to.eventually.deep.equal(expectedGrouping);
return expect(promise).to.be.fulfilled.and.to.eventually.deep.equal(
expectedGrouping
);
});

@@ -255,7 +359,14 @@ });

const numberOfGroupings = faker.random.number({ min: 1, max: 10 });
expectedGrouping = fixture.buildList('facilityGrouping', numberOfGroupings);
groupingsFromServer = fixture.buildList('facilityGrouping', numberOfGroupings);
expectedGrouping = fixture.buildList(
'facilityGrouping',
numberOfGroupings
);
groupingsFromServer = fixture.buildList(
'facilityGrouping',
numberOfGroupings
);
expectedOrganizationId = fixture.build('organization').id;
formatGroupingFromServer = this.sandbox.stub(facilitiesUtils, 'formatGroupingFromServer')
formatGroupingFromServer = this.sandbox
.stub(facilitiesUtils, 'formatGroupingFromServer')
.callsFake((grouping, index) => expectedGrouping[index]);

@@ -267,4 +378,10 @@ request = {

const facilityGroupings = new FacilityGroupings(baseSdk, request, expectedHost);
promise = facilityGroupings.getAllByOrganizationId(expectedOrganizationId);
const facilityGroupings = new FacilityGroupings(
baseSdk,
request,
expectedHost
);
promise = facilityGroupings.getAllByOrganizationId(
expectedOrganizationId
);
});

@@ -280,4 +397,6 @@

return promise.then(() => {
expect(formatGroupingFromServer).to.have.callCount(groupingsFromServer.length);
groupingsFromServer.forEach((grouping) => {
expect(formatGroupingFromServer).to.have.callCount(
groupingsFromServer.length
);
groupingsFromServer.forEach(grouping => {
expect(formatGroupingFromServer).to.be.calledWith(grouping);

@@ -289,4 +408,5 @@ });

it('returns a fulfilled promise with the facility groupings', function() {
return expect(promise).to.be.fulfilled
.and.to.eventually.deep.equal(expectedGrouping);
return expect(promise).to.be.fulfilled.and.to.eventually.deep.equal(
expectedGrouping
);
});

@@ -297,3 +417,7 @@ });

it('returns a rejected promise with an error when no organizationId is provided', function() {
const facilityGroupings = new FacilityGroupings(baseSdk, baseRequest, expectedHost);
const facilityGroupings = new FacilityGroupings(
baseSdk,
baseRequest,
expectedHost
);
const promise = facilityGroupings.getAllByOrganizationId();

@@ -316,3 +440,7 @@

const facilityGroupings = new FacilityGroupings(baseSdk, baseRequest, expectedHost);
const facilityGroupings = new FacilityGroupings(
baseSdk,
baseRequest,
expectedHost
);
promise = facilityGroupings.removeFacility(

@@ -345,3 +473,7 @@ facilityGroupingFacility.facilityGroupingId,

const facilityGroupings = new FacilityGroupings(baseSdk, baseRequest, expectedHost);
const facilityGroupings = new FacilityGroupings(
baseSdk,
baseRequest,
expectedHost
);
const promise = facilityGroupings.removeFacility(

@@ -357,2 +489,120 @@ groupingFacility.facilityGroupingId,

});
describe('update', function() {
context('when all required information is available', function() {
let formatGroupingFromServer;
let formatGroupingToServer;
let formattedGroupingFromServer;
let formattedUpdateToServer;
let groupingFromServer;
let promise;
let request;
let update;
beforeEach(function() {
formattedGroupingFromServer = fixture.build('facilityGrouping');
groupingFromServer = fixture.build(
'facilityGrouping',
formattedGroupingFromServer,
{
fromServer: true
}
);
update = omit(formattedGroupingFromServer, [
'createdAt',
'id',
'organizationId',
'ownerId',
'updatedAt'
]);
formattedUpdateToServer = fixture.build('facilityGrouping', update, {
fromServer: true
});
formatGroupingFromServer = this.sandbox
.stub(facilitiesUtils, 'formatGroupingFromServer')
.returns(formattedGroupingFromServer);
formatGroupingToServer = this.sandbox
.stub(facilitiesUtils, 'formatGroupingToServer')
.returns(formattedUpdateToServer);
request = {
...baseRequest,
put: this.sandbox.stub().resolves(groupingFromServer)
};
const facilityGroupings = new FacilityGroupings(
baseSdk,
request,
expectedHost
);
promise = facilityGroupings.update(
formattedGroupingFromServer.id,
update
);
});
it('formats the facility grouping update for the server', function() {
expect(formatGroupingToServer).to.be.calledWith(update);
});
it('updates the facility groupings', function() {
expect(request.put).to.be.calledWith(
`${expectedHost}/groupings/${formattedGroupingFromServer.id}`,
formattedUpdateToServer
);
});
it('formats the returned facility grouping', function() {
return promise.then(() => {
expect(formatGroupingFromServer).to.be.calledWith(groupingFromServer);
});
});
it('returns a fulfilled promise with the updated facility grouping', function() {
return expect(promise).to.be.fulfilled.and.to.eventually.equal(
formattedGroupingFromServer
);
});
});
});
context(
'when there is missing or malformed required information',
function() {
let facilityGroupings;
beforeEach(function() {
facilityGroupings = new FacilityGroupings(baseSdk, baseRequest);
});
it('throws an error when there is no provided facility grouping id', function() {
const groupingUpdate = fixture.build('facilityGrouping');
const promise = facilityGroupings.update(null, groupingUpdate);
return expect(promise).to.be.rejectedWith(
'A facility grouping id is required to update a facility grouping.'
);
});
it('throws an error when there is no update provided', function() {
const groupingUpdate = fixture.build('facilityGrouping');
const promise = facilityGroupings.update(groupingUpdate.id);
return expect(promise).to.be.rejectedWith(
'An update is required to update a facility grouping'
);
});
it('throws an error when the update is not an object', function() {
const groupingUpdate = fixture.build('facilityGrouping');
const promise = facilityGroupings.update(groupingUpdate.id, [
groupingUpdate
]);
return expect(promise).to.be.rejectedWith(
'The facility grouping update must be a well-formed object with the data you wish to update.'
);
});
}
);
});

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