Skip to content

Commit 926d724

Browse files
committed
add tests
1 parent 7f3985e commit 926d724

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

tests/unit/auth/Vault.spec.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ describe('Vault class', () => {
7777
getEmailAddresses: sandbox.stub(),
7878
getAccountIds: sandbox.stub(),
7979
getCanonicalIdsByAccountIds: sandbox.stub(),
80+
getAccountLimitsByCanonicalIds: sandbox.stub(),
8081
checkPolicies: sandbox.stub(),
8182
getOrCreateEncryptionKeyId: sandbox.stub(),
8283
};
@@ -579,6 +580,73 @@ describe('Vault class', () => {
579580
});
580581
});
581582

583+
describe('getAccountLimitsByCanonicalId', () => {
584+
const limitConfig = { RequestsPerSecond: { Limit: 1500 } };
585+
586+
it('should return the limit config for the canonical ID', done => {
587+
const mockResponse = {
588+
message: { body: { canonical123: limitConfig } },
589+
};
590+
mockClient.getAccountLimitsByCanonicalIds.callsFake((_, __, cb) => cb(null, mockResponse));
591+
592+
vault.getAccountLimitsByCanonicalId('canonical123', log, (err, data) => {
593+
assert.strictEqual(err, null);
594+
assert.deepStrictEqual(data, limitConfig);
595+
done();
596+
});
597+
});
598+
599+
it('should pass the canonical ID as a single-item list and the log options', done => {
600+
const mockResponse = {
601+
message: { body: { canonical123: limitConfig } },
602+
};
603+
mockClient.getAccountLimitsByCanonicalIds.callsFake((canonicalIds, options, cb) => {
604+
assert.deepStrictEqual(canonicalIds, ['canonical123']);
605+
assert.strictEqual(options.reqUid, log.getSerializedUids());
606+
assert.strictEqual(options.logger, log);
607+
cb(null, mockResponse);
608+
});
609+
610+
vault.getAccountLimitsByCanonicalId('canonical123', log, err => {
611+
assert.strictEqual(err, null);
612+
assert(mockClient.getAccountLimitsByCanonicalIds.calledOnce);
613+
done();
614+
});
615+
});
616+
617+
it('should return undefined when the canonical ID is absent from the response', done => {
618+
const mockResponse = { message: { body: {} } };
619+
mockClient.getAccountLimitsByCanonicalIds.callsFake((_, __, cb) => cb(null, mockResponse));
620+
621+
vault.getAccountLimitsByCanonicalId('canonical123', log, (err, data) => {
622+
assert.strictEqual(err, null);
623+
assert.strictEqual(data, undefined);
624+
done();
625+
});
626+
});
627+
628+
it('should return undefined when the client does not implement the method', done => {
629+
delete mockClient.getAccountLimitsByCanonicalIds;
630+
631+
vault.getAccountLimitsByCanonicalId('canonical123', log, (err, data) => {
632+
assert.strictEqual(err, null);
633+
assert.strictEqual(data, undefined);
634+
done();
635+
});
636+
});
637+
638+
it('should return error when client fails', done => {
639+
const mockError = new Error('Client error');
640+
mockClient.getAccountLimitsByCanonicalIds.callsFake((_, __, cb) => cb(mockError));
641+
642+
vault.getAccountLimitsByCanonicalId('canonical123', log, (err, data) => {
643+
assert.strictEqual(err, mockError);
644+
assert.strictEqual(data, undefined);
645+
done();
646+
});
647+
});
648+
});
649+
582650
describe('checkPolicies', () => {
583651
it('should return authorization results', done => {
584652
const mockParams = [{ test: 'param' }];

0 commit comments

Comments
 (0)