-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix(#512): converted user to API-compatible shape for AM user crea…
…tion method
- Loading branch information
1 parent
95436e8
commit a721ab7
Showing
2 changed files
with
51 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ var jsonStub = testbase.jsonLogStub; | |
var infoStub = testbase.infoLogStub; | ||
|
||
describe('Tests for lib/user.js', function() { | ||
|
||
var organization = 'myorg'; | ||
var user = proxyquire('../../lib/user', { | ||
'request': requestStub, | ||
'./auth': { | ||
|
@@ -28,7 +28,7 @@ describe('Tests for lib/user.js', function() { | |
}, | ||
'./org': { | ||
'getOrg' : function (id, undefined, callback) { | ||
callback(undefined, { id : 'myorg' }); | ||
callback(undefined, { id : organization }); | ||
} | ||
} | ||
}); | ||
|
@@ -37,25 +37,25 @@ describe('Tests for lib/user.js', function() { | |
firstName : 'John', | ||
lastName : 'Doe', | ||
displayName : 'John Doe', | ||
userState : 'ok', | ||
userState : 'ENABLED', | ||
roles : ['admin','expert','ECOM_ADMIN','ECOM_USER'], | ||
roleTenantFilter : 'expert:here,there;ECOM_ADMIN:zzzz_stg;ECOM_USER:zzzz_prd', | ||
primaryOrganization : 'doe org', | ||
primaryOrganization : organization, | ||
mail : '[email protected]', | ||
organizations : ['doe org','other org'], | ||
organizations : [organization], | ||
externalNames : 'foo', | ||
links : 'coding' | ||
}; | ||
var cleanUserObj = { | ||
firstName : 'John', | ||
lastName : 'Doe', | ||
displayName : 'John Doe', | ||
userState : 'ok', | ||
userState : 'ENABLED', | ||
roles : ['admin','expert','ECOM_ADMIN','ECOM_USER'], | ||
roleTenantFilter : {expert : ['here', 'there'],'bm-admin':['zzzz_stg'],'bm-user':['zzzz_prd']}, | ||
primaryOrganization : 'doe org', | ||
primaryOrganization : organization, | ||
mail : '[email protected]', | ||
organizations : ['doe org','other org'] | ||
organizations : [organization] | ||
}; | ||
|
||
var localUserObj = { | ||
|
@@ -71,13 +71,37 @@ describe('Tests for lib/user.js', function() { | |
}); | ||
|
||
it('makes a post request', function() { | ||
user.cli.create('myorg', undefined, '[email protected]', 'John', 'Doe', true); | ||
user.cli.create(organization, undefined, '[email protected]', 'John', 'Doe', true); | ||
|
||
const reqArgs = requestStub.getCall(0).args[0]; | ||
expect(reqArgs.uri).to.equal('https://am.host/dw/rest/v1/users'); | ||
expect(reqArgs.method).to.equal('POST'); | ||
}); | ||
|
||
it('makes request to create user with correct parameters', function() { | ||
var user = proxyquire('../../lib/user', { | ||
'request': function (opts, callback) { | ||
callback(undefined, {statusCode: 200}, opts.body); | ||
}, | ||
'./auth': { | ||
'getToken' : () => 'mytoken', | ||
'getAMHost' : () => 'am.host' | ||
}, | ||
'./log': { | ||
'json' : jsonStub | ||
}, | ||
'./org': { | ||
'getOrg' : function (id, undefined, callback) { | ||
callback(undefined, { id : organization }); | ||
} | ||
} | ||
}); | ||
user.cli.create(organization, cleanUserObj, '[email protected]', 'John', 'Doe', true); | ||
|
||
const logArgs = jsonStub.getCall(0).args; | ||
expect(logArgs[0]).to.eql(cleanUserObj); | ||
}); | ||
|
||
it('returns the created user', function() { | ||
var user = proxyquire('../../lib/user', { | ||
'request': function (opts, callback) { | ||
|
@@ -96,13 +120,14 @@ describe('Tests for lib/user.js', function() { | |
} | ||
} | ||
}); | ||
user.cli.create('myorg', undefined, '[email protected]', 'John', 'Doe', true); | ||
user.cli.create(organization, undefined, '[email protected]', 'John', 'Doe', true); | ||
|
||
const logArgs = jsonStub.getCall(0).args; | ||
expect(logArgs[0]).to.eql(cleanUserObj); | ||
}); | ||
}); | ||
|
||
|
||
describe('cli.list function', function() { | ||
|
||
beforeEach(function() { | ||
|
@@ -122,11 +147,11 @@ describe('Tests for lib/user.js', function() { | |
}, | ||
'./org': { | ||
'getOrg' : function (id, undefined, callback) { | ||
callback(undefined, { id : 'myorg' }); | ||
callback(undefined, { id : organization }); | ||
} | ||
} | ||
}); | ||
user.cli.list('myorg', null, null, null, true, undefined); | ||
user.cli.list(organization, null, null, null, true, undefined); | ||
|
||
const reqArgs = requestStub.getCall(0).args[0]; | ||
expect(reqArgs.uri).to.equal('https://am.host/dw/rest/v1/users?page=0&size=25'); | ||
|
@@ -147,11 +172,11 @@ describe('Tests for lib/user.js', function() { | |
}, | ||
'./org': { | ||
'getOrg' : function (id, undefined, callback) { | ||
callback(undefined, { id : 'myorg' }); | ||
callback(undefined, { id : organization }); | ||
} | ||
} | ||
}); | ||
user.cli.list('myorg', null, null, null, true, undefined); | ||
user.cli.list(organization, null, null, null, true, undefined); | ||
|
||
const logArgs = jsonStub.getCall(0).args; | ||
expect(logArgs[0]).to.eql([{id:1,firstName:'John'},{id:2,firstName:'Jane'}]); | ||
|
@@ -171,11 +196,11 @@ describe('Tests for lib/user.js', function() { | |
}, | ||
'./org': { | ||
'getOrg' : function (id, undefined, callback) { | ||
callback(undefined, { id : 'myorg' }); | ||
callback(undefined, { id : organization }); | ||
} | ||
} | ||
}); | ||
user.cli.list('myorg', null, '[email protected]', null, true, undefined); | ||
user.cli.list(organization, null, '[email protected]', null, true, undefined); | ||
|
||
const logArgs = jsonStub.getCall(0).args; | ||
expect(logArgs[0]).to.eql({id:1,firstName:'John'}); | ||
|
@@ -211,7 +236,7 @@ describe('Tests for lib/user.js', function() { | |
}, | ||
'./org': { | ||
'getOrg' : function (id, undefined, callback) { | ||
callback(undefined, { id : 'myorg' }); | ||
callback(undefined, { id : organization }); | ||
} | ||
} | ||
}); | ||
|