-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from owncloud/config-loading
Config loading
- Loading branch information
Showing
11 changed files
with
143 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Enhancement: Allow string as configObject attribute | ||
|
||
The property/attribute "configObject" is now allowed to be a string. We'll parse it as JSON. | ||
|
||
https://github.com/owncloud/file-picker/pull/27 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"version": "0.2.0", | ||
"author": "ownclouders <[email protected]>", | ||
"description": "Easily integrate ownCloud into your existing products", | ||
"type": "module", | ||
"type": "commonjs", | ||
"module": "dist/file-picker.js", | ||
"main": "dist/file-picker.js", | ||
"unpkg": "dist/file-picker.min.js", | ||
|
@@ -44,17 +44,18 @@ | |
"vue-virtual-scroller": "^1.0.10" | ||
}, | ||
"devDependencies": { | ||
"@babel/eslint-parser": "^7.13.14", | ||
"@babel/polyfill": "^7.10.4", | ||
"@vue/cli-plugin-babel": "^4.4.0", | ||
"@vue/cli-plugin-eslint": "^4.4.0", | ||
"@vue/cli-plugin-unit-jest": "^4.4.0", | ||
"@vue/cli-service": "^4.4.0", | ||
"@vue/eslint-config-prettier": "^6.0.0", | ||
"@vue/test-utils": "^1.0.3", | ||
"babel-eslint": "^10.1.0", | ||
"eslint": "^6.7.2", | ||
"eslint-plugin-prettier": "^3.1.3", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"eslint-plugin-vue": "^6.2.2", | ||
"jest-fetch-mock": "^3.0.3", | ||
"prettier": "^1.19.1", | ||
"vue": "^2.6.12", | ||
"vue-template-compiler": "^2.6.12" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Identify which way of configuring the file picker was chosen and return a config object from it, | ||
* either by fetching, parsing or plain returning it. | ||
* | ||
* @param configObject object|string|null Either an object or a json string holding the config | ||
* @param configLocation string A config url | ||
* @returns {Promise<any>} | ||
*/ | ||
export async function loadConfig(configObject, configLocation) { | ||
if (configObject === null) { | ||
const config = await fetch(configLocation) | ||
return await config.json() | ||
} | ||
|
||
if (typeof configObject === 'string') { | ||
return JSON.parse(configObject) | ||
} | ||
|
||
return configObject | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import fetchMock from 'jest-fetch-mock' | ||
fetchMock.enableMocks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { loadConfig } from '@/helpers/config' | ||
|
||
const exampleConfig = { | ||
server: 'https://own.cloud/', | ||
auth: { | ||
clientId: 'rWgSlOtLJCO6QBtEVgDdXWlUOrEt2CBL9F48c6TQKt3ZGG5ofazNhEJjp6TlyanT', | ||
url: 'https://own.cloud/index.php/apps/oauth2/api/v1/token', | ||
authUrl: 'https://own.cloud/index.php/apps/oauth2/authorize' | ||
} | ||
} | ||
|
||
describe('FilePicker config', () => { | ||
describe('loadConfig', () => { | ||
it('When no configObject is provided, then the config is fetched from the configLocation', async () => { | ||
fetch.mockResponseOnce(JSON.stringify(exampleConfig)) | ||
const config = await loadConfig(null, 'https://whatever.location/config.json') | ||
expect(config).toEqual(exampleConfig) | ||
}) | ||
it('When a configObject is provided and of type string, it is parsed as JSON', async () => { | ||
const config = await loadConfig(JSON.stringify(exampleConfig), null) | ||
expect(config).toEqual(exampleConfig) | ||
}) | ||
it('When a configObject is provided and not of type string, it is returned without modification', async () => { | ||
const config = await loadConfig(exampleConfig, null) | ||
expect(config).toEqual(exampleConfig) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.