Skip to content

Commit

Permalink
Add unit test to coverage setConfigField and fix syntax error
Browse files Browse the repository at this point in the history
Update to latest strapi release 4.10.5
  • Loading branch information
Lith committed May 15, 2023
1 parent 07eb841 commit fd484f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ For old version, please refer to older release.

| Version | Supported |
|---------|--------------------|
| 4.10.2 | :white_check_mark: |
| 4.10.5 | :white_check_mark: |
| 4.10.2 | :x: |
| 4.10.1 | :white_check_mark: |
| 4.6.1 | :white_check_mark: |
| 4.5.6 | :white_check_mark: |
Expand Down
3 changes: 2 additions & 1 deletion lib/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const setConfigField = (fieldValue, defaultValue) => {
default:
return defaultValue;
}
}
};

/**
* Check validity of Service Account configuration
Expand Down Expand Up @@ -303,6 +303,7 @@ const init = (providerConfig) => {
module.exports = {
get,
checkServiceAccount,
setConfigField,
checkBucket,
mergeConfigs,
generateUploadFileName,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@strapi-community/strapi-provider-upload-google-cloud-storage",
"version": "4.10.2",
"version": "4.10.5",
"description": "(Non-official) Google Cloud Storage Provider for Strapi Upload",
"keywords": [
"strapi",
Expand Down
23 changes: 23 additions & 0 deletions test/lib/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const slugify = require('slugify');
const {
checkServiceAccount,
checkBucket,
setConfigField,
mergeConfigs,
generateUploadFileName,
init,
Expand Down Expand Up @@ -202,6 +203,28 @@ describe('/lib/provider.js', () => {
});
});

describe('#setConfigField', () => {
describe('when config field is undefined', () => {
it('must return default value true', async () => {
await assert.equal(setConfigField(undefined, true), true);
});
it('must return default value false', async () => {
await assert.equal(setConfigField(undefined, false), false);
});
it('must return error if not a string with true or false value', async () => {
let fieldValue = 'undefined';
const error = new Error(`Invalid boolean value for ${fieldValue}!`);
assert.throws(() => setConfigField(fieldValue, true), error);
});
it('must return true boolean value if boolean value is true and default value is false', async () => {
await assert.equal(setConfigField(true, false), true);
});
it('must return true boolean value if boolean value is true and default value is true', async () => {
await assert.equal(setConfigField(false, true), false);
});
});
});

describe('#mergeConfigs', () => {
let strapiOriginal;

Expand Down

0 comments on commit fd484f0

Please sign in to comment.