it('.find $like', async function() { const post = await Post.findOne({ title: { $like: '%Post%' } }); expect(post.title).to.match(/Post/); });
it('listQueue with invalid accessKeyID', async function() { var client = new Client('accountid', { accessKeyID: 'invalidAccessKeyID', accessKeySecret: 'invalidAccessKeySecret', region: 'cn-shanghai' }); try { await client.listQueue(); } catch (ex) { expect(ex.name).to.be('MNSInvalidAccessKeyIdError'); expect(ex.message).to.match(/GET http:\/\/accountid\.mns\.cn-shanghai\.aliyuncs\.com\/queues failed with 403\. requestid: .{24}, hostid: http:\/\/accountid.mns.cn-shanghai.aliyuncs.com, message: The access Id you provided is not exist\./); } });
it('buildHeaders should ok with securityToken', function () { const client = new ROAClient({ endpoint: 'https://ecs.aliyuncs.com/', apiVersion: '1.0', accessKeyId: 'accessKeyId', accessKeySecret: 'accessKeySecret', securityToken: 'securityToken' }); const headers = client.buildHeaders(); expect(headers).to.only.have.keys('accept', 'date', 'host', 'x-acs-signature-nonce', 'x-acs-signature-method', 'x-acs-signature-version', 'x-acs-version', 'x-sdk-client', 'x-acs-accesskey-id', 'x-acs-security-token', 'user-agent'); expect(headers).to.have.property('accept', 'application/json'); expect(headers.date).to.match(/[A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} \d{2}:\d{2}:\d{2} GMT/); expect(headers).to.have.property('host', 'ecs.aliyuncs.com'); expect(headers['user-agent'].startsWith('AlibabaCloud')).to.be.ok(); });
.on('close', () => { expect(error).to.be.ok(); expect(error.toString()).to.match(new RegExp(`Table ${database}.random_table_name doesn\'t exist`));
} catch (ex) { expect(ex.name).to.be('FCundefinedError'); expect(ex.message).to.match(/GET .* failed with 502\. requestid: .{36}, message: Process exited unexpectedly before completing request.*/);
describe('lib/log', function() { describe('._fancify()', function() { it('should return colorful message + date', function() { expect(log._fancify('red', 'message')).to.match(
expect(e.message).to.match(/Execute function `obj.error` Error: mock error/); expect(e.message).to.match(/line 2/); }); }); }); }).to.throwException(function (e) { expect(e.message).to.match(/Execute function `obj.error` Error: obj is undefined or null/); expect(e.message).to.match(/line 2/); }); });
it('listServices with invalid accessKeyID', function () { return (async function () { var client = new FunctionComputeClient('accountid', { accessKeyID: 'invalidAccessKeyID', accessKeySecret: 'invalidAccessKeySecret', region: 'cn-shanghai' }); try { await client.listServices(); } catch (ex) { expect(ex.name).to.be('FCInvalidAccessKeyIDError'); expect(ex.message).to.match(/GET \/services failed with 403\. requestid: .{36}, message: invalid access key ID 'invalidAccessKeyID'./); } })(); });
it('listServices with invalid accessKeySecret', function () { return (async function () { var client = new FunctionComputeClient('accountid', { accessKeyID: ACCESS_KEY_ID, accessKeySecret: 'invalidAccessKeySecret', region: 'cn-shanghai' }); try { await client.listServices(); } catch (ex) { expect(ex.name).to.be('FCSignatureNotMatchError'); expect(ex.message).to.match(/GET \/services failed with 403\. requestid: .{36}, message: The request signature we calculated does not match the signature you provided\./); } })(); });
it('listQueue with invalid accessKeySecret', function () { return (async function() { var client = new Client('accountid', { accessKeyID: ACCESS_KEY_ID, accessKeySecret: 'invalidAccessKeySecret', region: 'cn-shanghai' }); try { await client.listQueue(); } catch (ex) { expect(ex.name).to.be('MNSAccessDeniedError'); expect(ex.message).to.match(/GET http:\/\/accountid.mns.cn-shanghai.aliyuncs.com\/queues failed with 403. requestid: .{24}, hostid: http:\/\/accountid.mns.cn-shanghai.aliyuncs.com, message: The OwnerId that your Access Key Id associated to is forbidden for this operation./); } })(); });
it('buildHeaders should ok', function () { const client = new ROAClient({ endpoint: 'https://ecs.aliyuncs.com/', apiVersion: '1.0', accessKeyId: 'accessKeyId', accessKeySecret: 'accessKeySecret', }); const headers = client.buildHeaders(); expect(headers).to.only.have.keys('accept', 'date', 'host', 'x-acs-signature-nonce', 'x-acs-signature-method', 'x-acs-signature-version', 'x-acs-version', 'x-sdk-client', 'user-agent'); expect(headers).to.have.property('accept', 'application/json'); expect(headers.date).to.match(/[A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} \d{2}:\d{2}:\d{2} GMT/); expect(headers).to.have.property('host', 'ecs.aliyuncs.com'); expect(headers['user-agent'].startsWith('AlibabaCloud')).to.be.ok(); });