Skip to content

Commit

Permalink
quota to bigInt relative changes
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Jan 17, 2025
1 parent 37f5dbb commit abb4d2e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@
"new-parens": "off",
"no-multi-spaces": "off",
"quote-props": "off"
},
"globals": {
"BigInt": "readonly"
}
}
4 changes: 2 additions & 2 deletions lib/IAMClient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ declare class VaultClient {
* Update Quota of an account
*
* @param {string} accountName - account name
* @param {number} quota - maximum quota for the account
* @param {bigint} quota - maximum quota for the account
* @param {VaultClient~requestCallback} callback - callback
* @returns {undefined}
*/
updateAccountQuota(accountName: string, quota: number, callback: any): undefined;
updateAccountQuota(accountName: string, quota: bigint, callback: any): undefined;
/**
* Delete Quota of an account
*
Expand Down
2 changes: 1 addition & 1 deletion lib/IAMClient.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions lib/IAMClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,9 @@ class VaultClient {
} = options;

if (quota) {
const conv = Number.isNaN(Number.parseInt(quota, 10));
assert(typeof quota === 'number'
&& !conv
&& quota >= 0, 'Quota must be a non-negative number');
data.quotaMax = quota;
assert(typeof quota === 'bigint'
&& quota >= BigInt(0), 'Quota must be a non-negative bigint');
data.quotaMax = quota.toString();
}
if (externalAccountId) {
const conv = Number.isNaN(Number.parseInt(externalAccountId, 10));
Expand Down Expand Up @@ -287,18 +285,18 @@ class VaultClient {
* Update Quota of an account
*
* @param {string} accountName - account name
* @param {number} quota - maximum quota for the account
* @param {bigint} quota - maximum quota for the account
* @param {VaultClient~requestCallback} callback - callback
* @returns {undefined}
*/
updateAccountQuota(accountName, quota, callback) {
const data = {
Action: 'UpdateAccountQuota',
Version: '2010-05-08',
quotaMax: quota,
quotaMax: quota.toString(),
};
const quotaIsValid = typeof quota === 'number' && !Number.isNaN(Number.parseInt(quota, 10)) && quota > 0;
assert(!this.parameterValidation || quotaIsValid, 'Quota must be a strictly positive number');
const quotaIsValid = typeof quota === 'bigint' && quota > BigInt(0);
assert(!this.parameterValidation || quotaIsValid, 'Quota must be a strictly positive bigint');
if (accountName) {
assert(!this.parameterValidation || typeof accountName === 'string',
'the account name, if set, should be a string');
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/updateAccountQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ describe('updateAccountQuota', () => {

it('should call the request method with the correct parameters when options are provided', () => {
client = createClient(true);
const quota = 100;
const quota = BigInt(100);
const accountName = 'exampleAccount';

const expectedData = {
Action: 'UpdateAccountQuota',
Version: '2010-05-08',
quotaMax: quota,
quotaMax: quota.toString(),
AccountName: 'exampleAccount',
};

Expand All @@ -37,12 +37,12 @@ describe('updateAccountQuota', () => {

it('should call the request method with the correct parameters when options are not provided', () => {
client = createClient(true);
const quota = 100;
const quota = BigInt(100);

const expectedData = {
Action: 'UpdateAccountQuota',
Version: '2010-05-08',
quotaMax: quota,
quotaMax: quota.toString(),
};

client.updateAccountQuota(undefined, quota, () => {});
Expand All @@ -54,31 +54,31 @@ describe('updateAccountQuota', () => {

it('should throw an error if the quota is not a strictly positive number', () => {
client = createClient(true);
const quota = -100;
const quota = BigInt(-100);

assert.throws(() => {
client.updateAccountQuota(undefined, quota, () => {});
}, /Quota must be a strictly positive number/);
}, /Quota must be a strictly positive bigint/);
});


it('should throw an error if the quota provided is 0', () => {
client = createClient(true);
const quota = 0;
const quota = BigInt(0);

assert.throws(() => {
client.updateAccountQuota(undefined, quota, () => {});
}, /Quota must be a strictly positive number/);
}, /Quota must be a strictly positive bigint/);
});

it('should not throw an error even when the quota is not a strictly positive number if ci is true', () => {
client = createClient(false);
const quota = -100;
const quota = BigInt(-100);

const expectedData = {
Action: 'UpdateAccountQuota',
Version: '2010-05-08',
quotaMax: quota,
quotaMax: quota.toString(),
};

client.updateAccountQuota(undefined, quota, () => {});
Expand All @@ -91,12 +91,12 @@ describe('updateAccountQuota', () => {

it('should not throw an error even when the quota is 0 if ci is true', () => {
client = createClient(false);
const quota = 0;
const quota = BigInt(0);

const expectedData = {
Action: 'UpdateAccountQuota',
Version: '2010-05-08',
quotaMax: quota,
quotaMax: quota.toString(),
};

client.updateAccountQuota(undefined, quota, () => {});
Expand All @@ -108,7 +108,7 @@ describe('updateAccountQuota', () => {

it('should throw an error if accountName is not a string', () => {
client = createClient(true);
const quota = 100;
const quota = BigInt(100);
const accountName = 123;

assert.throws(() => {
Expand Down

0 comments on commit abb4d2e

Please sign in to comment.