it('should handle properly situation when email returned from facebook is empty', function (done) { var $u = createUser(); $u.profile._json = { email: null }; userRepo.createAccFromFacebook($u.accessToken, $u.refreshToken, $u.profile) .then(function(user) { expect(user).to.be.a('object'); expect(user.facebookId).to.be($u.uniqueness.toString()); expect(user.password).to.be(null); expect(user.email).to.be(user.facebookId + '@facebook.com'); done(); }); });
describe('parseJson', function() { it('Should return valid JSON object from string', function() { expect(utils.parseJson('{ "unicorn": "foo" }')).to.eql({ unicorn: 'foo' }); }); it('Should return undefined without throwing error when parsing invalid JSON string', function() { expect(utils.parseJson('{ "unicorn": foo }')).to.be(undefined); }); });
it('updateService should ok', async function () { const service = await client.updateService(serviceName, { description: 'this is test update service' }); expect(service.data).to.be.ok(); expect(service.data).to.have.property('serviceName', serviceName); expect(service.data).to.have.property('description', 'this is test update service'); });
before(async function () { // clean up try { await client.deleteService(serviceName); } catch (ex) { // Ignore } const service = await client.createService(serviceName); expect(service.data).to.be.ok(); expect(service.data).to.have.property('serviceName', serviceName); });
it('invokeFunction with rawBuf=false should return string', async function () { const response = await client.invokeFunction(serviceName, functionName, Buffer.from('world'), {}, 'LATEST', { rawBuf: false }); expect(response.data).a('string'); expect(response.data).to.be('hello world'); });
it('should create properly a new user from twitter with picture', function (done) { var $u = createUser(); $u.profile._json.profile_image_url_https = 'PICTURE_URL'; userRepo.createAccFromTwitter($u.accessToken, $u.tokenSecret, $u.profile) .then(function(user) { expect(user).to.be.a('object'); expect(user.profile).to.be.a('object'); expect(user.profile.picture).to.be('PICTURE_URL'); done(); }); });
it('signature should ok', function () { const client = new ROAClient({ endpoint: 'https://ecs.aliyuncs.com/', apiVersion: '1.0', accessKeyId: 'accessKeyId', accessKeySecret: 'accessKeySecret', securityToken: 'securityToken' }); const sign = client.signature('stringtosign'); expect(sign).to.be('9/j11e+L9jW8mC9eUA23Wn3c0fs='); });
it('should create properly a new user where there is no email returned from GitHub', function (done) { var $u = createUser(); $u.profile.emails = [ {value: ''} ]; userRepo.createAccFromGithub($u.accessToken, $u.tokenSecret, $u.profile) .then(function(user) { expect(user).to.be.a('object'); expect(user.profile).to.be.a('object'); expect(user.email).to.be($u.uniqueness + '@github.com'); done(); }); });
it('getCanonicalizedResource should ok', function () { const getCanonicalizedResource = roa.__get__('getCanonicalizedResource'); expect(getCanonicalizedResource('/', {})).to.be('/'); expect(getCanonicalizedResource('/', {key: 'value'})).to.be('/?key=value'); const q = {key: 'value', 'key1': 'value2'}; expect(getCanonicalizedResource('/', q)).to.be('/?key=value&key1=value2'); });
it('listServices should ok', async function () { const response = await client.listServices(); expect(response.data).to.be.ok(); expect(response.data.services).to.be.ok(); expect(response.data.services.length).to.above(0); const [service] = response.data.services; expect(service).to.have.property('serviceName'); });
it('invokeFunction should ok', async function () { const response = await client.invokeFunction(serviceName, functionName, 'world', {}, 'LATEST'); expect(response.data).to.be('hello world'); const initResponse_1 = await client.invokeFunction(serviceName, initFunctionName, null); expect(initResponse_1.data).to.be('2'); const initResponse_2 = await client.invokeFunction(serviceName, initFunctionName, null); expect(initResponse_2.data).to.be('3'); });
it('should create properly a new user from google with picture', function (done) { var $u = createUser(); $u.profile._json.image = {url: 'PICTURE_URL'}; userRepo.createAccFromGoogle($u.accessToken, $u.tokenSecret, $u.profile) .then(function(user) { expect(user).to.be.a('object'); expect(user.profile).to.be.a('object'); expect(user.profile.picture).to.be('PICTURE_URL'); done(); }); });
it('invokeFunction should faster', async function () { const response = await client.invokeFunction(serviceName, functionName, Buffer.from('world')); expect(response.data).a('string'); expect(response.data).to.be('hello world'); });