Skip to content

Commit

Permalink
Read Operator resource data (#38)
Browse files Browse the repository at this point in the history
* Read Operator resource data

* Update CDN URL

* 5.10.1
  • Loading branch information
C-D-Lewis authored Dec 3, 2020
1 parent 5e75fbd commit 0b2cf24
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import * as evrythng from 'evrythng'
Or use a simple script tag to load it from the CDN.

```html
<script src="https://d10ka0m22z5ju5.cloudfront.net/js/evrythng/5.10.0/evrythng-5.10.0.js"></script>
<script src="https://d10ka0m22z5ju5.cloudfront.net/js/evrythng/5.10.1/evrythng-5.10.1.js"></script>
```

Then use in a browser `script` tag using the `evrythng` global variable:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "evrythng",
"version": "5.10.0",
"version": "5.10.1",
"description": "Official Javascript SDK for the EVRYTHNG API.",
"main": "./dist/evrythng.node.js",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions src/scope/Operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default class Operator extends OperatorAccess(Scope) {
this.id = access.actor.id
this[symbols.path] = this._getPath()
})
.then(() => this.read())
}

/**
Expand Down Expand Up @@ -96,11 +97,11 @@ export default class Operator extends OperatorAccess(Scope) {
// PRIVATE

/**
* Return operator access endpoint.
* Return operator endpoint.
*
* @return {string}
*/
_getPath () {
return '/access'
return `/operators/${this.id}`
}
}
16 changes: 15 additions & 1 deletion test/e2e/scope/operator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,30 @@ module.exports = () => {
operator = getScope('operator')
})

it('should read Operator resource', async () => {
expect(operator.id).to.equal('operatorId')
expect(operator.email).to.equal('[email protected]')
expect(operator.firstName).to.equal('Test')
expect(operator.lastName).to.equal('User')
})

it('should allow self-same Operator update', async () => {
mockApi().put('/operators/operatorId')
.reply(200, {})
.reply(200, {
customFields: { foo: 'bar' }
})
const res = await operator.update({
customFields: {
foo: 'bar'
}
})

// Response should be accurate of new state
expect(res).to.be.an('object')
expect(res.customFields.foo).to.equal('bar')

// Operator should have updated state
expect(operator.customFields.foo).to.equal('bar')
})
})
}
8 changes: 8 additions & 0 deletions test/e2e/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ const mockApi = (apiUrl = API_URL) => nock(apiUrl)
*/
const setup = async () => {
mockApi().get('/access').reply(200, { actor: { id: 'operatorId' } })
mockApi().get('/operators/operatorId').reply(200, {
id: 'operatorId',
createdAt: 1471862430968,
updatedAt: 1607002260749,
email: '[email protected]',
firstName: 'Test',
lastName: 'User',
})
const operator = new Operator(OPERATOR_API_KEY)
await operator.init()

Expand Down

0 comments on commit 0b2cf24

Please sign in to comment.