Skip to content

Commit

Permalink
Add JS coverage for the User API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jbachelet committed Feb 10, 2021
1 parent 074cc74 commit 6b38cc5
Show file tree
Hide file tree
Showing 5 changed files with 743 additions and 84 deletions.
204 changes: 202 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ The API is structured into sub modules. You may require sub modules directly, e.
const sfcc_code = require('sfcc-ci').code;
const sfcc_instance = require('sfcc-ci').instance;
const sfcc_job = require('sfcc-ci').job;
const sfcc_user = require('sfcc-ci').user;
const sfcc_webdav = require('sfcc-ci').webdav;
```
Expand All @@ -584,8 +585,18 @@ The following APIs are available (assuming `sfcc` refers to `require('sfcc-ci')`
sfcc.instance.upload(instance, file, token, options, callback);
sfcc.instance.import(instance, file_name, token, callback);
sfcc.job.run(instance, job_id, job_params, token, callback);
sfcc.job.status(instance, job_id, job_execution_id, token, callback);
sfcc.webdav.upload(instance, path, file, token, options, callback);
sfcc.user.create(org, user, mail, firstName, lastName, token).then(result => ...).catch(err => ...);
sfcc.user.list(org, role, login, count, sortBy, token).then(result => ...).catch(err => ...);
sfcc.user.update(login, changes, token).then(result => ...).catch(err => ...);
sfcc.user.grant(login, role, scope, token).then(result => ...).catch(err => ...);
sfcc.user.revoke(login, role, scope, token).then(result => ...).catch(err => ...);
sfcc.user.delete(login, purge, token).then(result => ...).catch(err => ...);
sfcc.user.createLocal(instance, login, user, token).then(result => ...).catch(err => ...);
sfcc.user.searchLocal(instance, login, query, role, sortBy, count, start, token).then(result => ...).catch(err => ...);
sfcc.user.updateLocal(instance, login, changes, token).then(result => ...).catch(err => ...);
sfcc.user.grantLocal(instance, login, role, token).then(result => ...).catch(err => ...);
sfcc.user.revokeLocal(instance, login, role, token).then(result => ...).catch(err => ...);
sfcc.user.deleteLocal(instance, login, token).then(result => ...).catch(err => ...);
```
### Authentication ###
Expand Down Expand Up @@ -785,6 +796,195 @@ callback | (Function) | Callback function executed as a result. The err
***
### User ###
APIs available in `require('sfcc').user`:
`create(org, user, mail, firstName, lastName, token)`
Creates a new user into Account Manager
Param | Type | Description
------------- | ------------| --------------------------------
org | (String) | The org ID where to create the user
user | (Object) | The user object with all the required data in it
mail | (String) | The email of the user
firstName | (String) | The firstname of the user
lastName | (String) | The lastname of the user
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is the newly created user object.
***
`list(org, role, login, count, sortBy, token)`
Lists all users eligible to manage from the Account Manager, based on the given filters (if any provided)
Param | Type | Description
------------- | ------------| --------------------------------
org | (String) | The org ID or null, if all users should be retrieved
role | (String) | The role or null, if all users should be retrieved
login | (String) | The login or null, if all users should be retrieved
count | (Number) | The max count of list items
sortBy | (String) | (Optional) field to sort the list of users by
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is the results array.
***
`update(login, changes, token)`
Update a user into Account Manager
Param | Type | Description
------------- | ------------| --------------------------------
login | (String) | The login of the user to update
changes | (Object) | The changes to the user details
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is the updated user.
***
`grant(login, role, scope, token)`
Grant a role to a user into Account Manager
Param | Type | Description
------------- | ------------| --------------------------------
login | (String) | The login (email) of the user
role | (String) | The role to grant
scope | (String) | The scope of the role to revoke
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is the changed user.
***
`revoke(login, role, scope, token)`
Revoke a role to a user from Account Manager
Param | Type | Description
------------- | ------------| --------------------------------
login | (String) | The login (email) of the user
role | (String) | The role to grant
scope | (String) | The scope of the role to revoke
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is the changed user.
***
`delete(login, purge, token)`
Delete a user from Account Manager
Param | Type | Description
------------- | ------------| --------------------------------
login | (String) | The user to delete
purge | (Boolean) | Whether to purge the user completely
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is a boolean value that confirms if the user has been deleted or not.
***
`createLocal(instance, login, user, token)`
Creates a new local user on an instance
Param | Type | Description
------------- | ------------| --------------------------------
instance | (String) | The instance to create the user on
login | (String) | The user to delete
user | (Object) | The user details
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is the created user.
***
`searchLocal(instance, login, query, role, sortBy, count, start, token)`
Search for local users on an instance
Param | Type | Description
------------- | ------------| --------------------------------
instance | (String) | The instance to create the user on
login | (String) | The login or null, if all users should be retrieved
query | (String) | The query to search users for
role | (String) | The role to search users for
sortBy | (String) | (Optional) field to sort users by
count | (Number) | (Optional) number of items per page
start | (Number) | (Optional) zero-based index of the first search hit to include
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is the results of the search.
***
`updateLocal(instance, login, changes, token)`
Update a local user on an instance
Param | Type | Description
------------- | ------------| --------------------------------
instance | (String) | The instance to update the user on
login | (String) | The login of the local user to update
changes | (Object) | The changes to the user details
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is the updated user.
***
`grantLocal(instance, login, role, token)`
Grant a role to a local user on an instance
Param | Type | Description
------------- | ------------| --------------------------------
instance | (String) | The instance to apply the role on the user on
login | (String) | The login of the local user to grant
role | (String) | The role to grant
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is the changed user.
***
`revokeLocal(instance, login, role, token)`
Revoke a role from a local user on an instance
Param | Type | Description
------------- | ------------| --------------------------------
instance | (String) | The instance to apply the role on the user on
login | (String) | The login of the local user to revoke
role | (String) | The role to revoke
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is the changed user.
***
`deleteLocal(instance, login, token)`
Delete a local user from an instance
Param | Type | Description
------------- | ------------| --------------------------------
instance | (String) | The instance to delete the user on
login | (String) | The login of the local user to delete
token | (String) | The Oauth token to use use for authentication
**Returns:** (Promise) The [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with its `resolve` or `reject` methods called respectively with the `result` or the `error`. The `result` variable here is a boolean value that confirms if the user has been deleted or not.
***
### WebDAV ###
APIs available in `require('sfcc').webdav`:
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ exports.cartridge = require('./lib/cartridge').api;
exports.code = require('./lib/code').api;
exports.instance = require('./lib/instance').api;
exports.job = require('./lib/job').api;
exports.user = require('./lib/user').api;
exports.webdav = require('./lib/webdav').api;
9 changes: 5 additions & 4 deletions lib/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ function getOptions(path, token, method) {
* Retrieves detals of an org
*
* @param {String} org the name of the org
* @param {String} token oauth token
* @param {Function} callback the callback to execute, the error and the org are available as arguments to the callback function
*/
function getOrg(org, callback) {
function getOrg(org, token, callback) {
// build the request options
var options = getOptions(API_BASE + '/organizations/search/findByName?startsWith=' + org + '&ignoreCase=false',
auth.getToken(), 'GET');
var options = getOptions(API_BASE + '/organizations/search/findByName?startsWith=' + encodeURIComponent(org) + '&ignoreCase=false',
token || auth.getToken(), 'GET');

// do the request
request(options, function (err, res, body) {
Expand Down Expand Up @@ -160,7 +161,7 @@ module.exports.cli = {
list : function(orgId, asJson, sortBy) {
// get details of a single org if org was passed
if ( typeof(orgId) !== 'undefined' && orgId !== null ) {
getOrg(orgId, function(err, org) {
getOrg(orgId, undefined, function(err, org) {
if (err) {
console.error(err.message);
return;
Expand Down
Loading

0 comments on commit 6b38cc5

Please sign in to comment.