Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert swagger changes, fix: broken link, feat: base reapit config #272

Merged
merged 3 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

![Pull Request](https://github.com/reapit/foundations/workflows/Pull%20Request/badge.svg)
![Release develop](https://github.com/reapit/foundations/workflows/Release%20develop/badge.svg)
![Release production](https://github.com/reapit/foundations/workflows/Release%20production/badge.svg)

This is the repository for the Reapit Foundations API, Marketplace, cloud applications and tooling.

Expand Down
117 changes: 8 additions & 109 deletions packages/config-manager/reapit-config.example.json
Original file line number Diff line number Diff line change
@@ -1,129 +1,28 @@
{
"LOCAL": {
"REAPIT_ENV": "",
"PLATFORM_BASE_URL": "",
"MARKETPLACE_BASE_URL": "",
"MARKET_PLACE_URL": "",
"REAPIT_ENV": "LOCAL",
"PLATFORM_API_BASE_URL": "https://dev.platform.reapit.cloud",
"MARKETPLACE_API_BASE_URL": "https://dev.platformmarketplace.reapit.cloud",
"MARKET_PLACE_URL": "https://dev.marketplace.reapit.cloud",
"MARKETPLACE_API_KEY": "",
"MARKETPLACE_GOOGLE_ANALYTICS_KEY": "",
"NODE_ENV": "",
"NODE_ENV": "development",
"NPM_TOKEN": "",
"GOOGLE_MAPS_API_KEY": "",
"COGNITO_USERPOOL_ID": "",
"COGNITO_OAUTH_URL": "",
"COGNITO_OAUTH_URL": "https://dev.connect.reapit.cloud",
"COGNITO_CLIENT_ID_MARKETPLACE": "",
"COGNITO_CLIENT_ID_GEO_DIARY": "",
"COGNITO_CLIENT_ID_AML_APP": "",
"COGNITO_CLIENT_ID_LTL_APP": "",
"COGNITO_API_BASE_URL": "",
"UPLOAD_FILE_BASE_URL": "",
"SWAGGER_BASE_URL": "",
"SWAGGER_BASE_URL": "https://dev.platform.reapit.cloud/docs",
"DEVELOPER_ACCOUNT_EMAIL": "",
"DEVELOPER_ACCOUNT_PASSWORD": "",
"CLIENT_ACCOUNT_EMAIL": "",
"CLIENT_ACCOUNT_PASSWORD": "",
"ADMIN_ACCOUNT_EMAIL": "",
"ADMIN_ACCOUNT_PASSWORD": "",
"APPLICATION_URL": "",
"RETRIES": 0,
"CHATBOT_APP_ID": "",
"SENTRY_PROJECT_URL_MARKETPLACE": "",
"SENTRY_PROJECT_URL_GEO_DIARY": "",
"SENTRY_PROJECT_URL_AML_APP": "",
"SENTRY_PROJECT_URL_LTL_APP": ""
},
"DEV": {
"REAPIT_ENV": "",
"PLATFORM_BASE_URL": "",
"MARKETPLACE_BASE_URL": "",
"MARKET_PLACE_URL": "",
"MARKETPLACE_API_KEY": "",
"MARKETPLACE_GOOGLE_ANALYTICS_KEY": "",
"NODE_ENV": "",
"NPM_TOKEN": "",
"GOOGLE_MAPS_API_KEY": "",
"COGNITO_USERPOOL_ID": "",
"COGNITO_OAUTH_URL": "",
"COGNITO_CLIENT_ID_MARKETPLACE": "",
"COGNITO_CLIENT_ID_GEO_DIARY": "",
"COGNITO_CLIENT_ID_AML_APP": "",
"COGNITO_CLIENT_ID_LTL_APP": "",
"COGNITO_API_BASE_URL": "",
"UPLOAD_FILE_BASE_URL": "",
"SWAGGER_BASE_URL": "",
"DEVELOPER_ACCOUNT_EMAIL": "",
"DEVELOPER_ACCOUNT_PASSWORD": "",
"CLIENT_ACCOUNT_EMAIL": "",
"CLIENT_ACCOUNT_PASSWORD": "",
"ADMIN_ACCOUNT_EMAIL": "",
"ADMIN_ACCOUNT_PASSWORD": "",
"APPLICATION_URL": "",
"RETRIES": 0,
"CHATBOT_APP_ID": "",
"SENTRY_PROJECT_URL_MARKETPLACE": "",
"SENTRY_PROJECT_URL_GEO_DIARY": "",
"SENTRY_PROJECT_URL_AML_APP": "",
"SENTRY_PROJECT_URL_LTL_APP": ""
},
"PROD": {
"REAPIT_ENV": "",
"PLATFORM_BASE_URL": "",
"MARKETPLACE_BASE_URL": "",
"MARKET_PLACE_URL": "",
"MARKETPLACE_API_KEY": "",
"MARKETPLACE_GOOGLE_ANALYTICS_KEY": "",
"NODE_ENV": "",
"NPM_TOKEN": "",
"GOOGLE_MAPS_API_KEY": "",
"COGNITO_USERPOOL_ID": "",
"COGNITO_OAUTH_URL": "",
"COGNITO_CLIENT_ID_MARKETPLACE": "",
"COGNITO_CLIENT_ID_GEO_DIARY": "",
"COGNITO_CLIENT_ID_AML_APP": "",
"COGNITO_CLIENT_ID_LTL_APP": "",
"COGNITO_API_BASE_URL": "",
"UPLOAD_FILE_BASE_URL": "",
"SWAGGER_BASE_URL": "",
"DEVELOPER_ACCOUNT_EMAIL": "",
"DEVELOPER_ACCOUNT_PASSWORD": "",
"CLIENT_ACCOUNT_EMAIL": "",
"CLIENT_ACCOUNT_PASSWORD": "",
"ADMIN_ACCOUNT_EMAIL": "",
"ADMIN_ACCOUNT_PASSWORD": "",
"APPLICATION_URL": "",
"RETRIES": 0,
"CHATBOT_APP_ID": "",
"SENTRY_PROJECT_URL_MARKETPLACE": "",
"SENTRY_PROJECT_URL_GEO_DIARY": "",
"SENTRY_PROJECT_URL_AML_APP": "",
"SENTRY_PROJECT_URL_LTL_APP": ""
},
"DEMO": {
"REAPIT_ENV": "",
"PLATFORM_BASE_URL": "",
"MARKETPLACE_BASE_URL": "",
"MARKET_PLACE_URL": "",
"MARKETPLACE_API_KEY": "",
"MARKETPLACE_GOOGLE_ANALYTICS_KEY": "",
"NODE_ENV": "",
"NPM_TOKEN": "",
"GOOGLE_MAPS_API_KEY": "",
"COGNITO_USERPOOL_ID": "",
"COGNITO_OAUTH_URL": "",
"COGNITO_CLIENT_ID_MARKETPLACE": "",
"COGNITO_CLIENT_ID_GEO_DIARY": "",
"COGNITO_CLIENT_ID_AML_APP": "",
"COGNITO_CLIENT_ID_LTL_APP": "",
"COGNITO_API_BASE_URL": "",
"UPLOAD_FILE_BASE_URL": "",
"SWAGGER_BASE_URL": "",
"DEVELOPER_ACCOUNT_EMAIL": "",
"DEVELOPER_ACCOUNT_PASSWORD": "",
"CLIENT_ACCOUNT_EMAIL": "",
"CLIENT_ACCOUNT_PASSWORD": "",
"ADMIN_ACCOUNT_EMAIL": "",
"ADMIN_ACCOUNT_PASSWORD": "",
"APPLICATION_URL": "",
"APPLICATION_URL": "http://localhost:8080",
"RETRIES": 0,
"CHATBOT_APP_ID": "",
"SENTRY_PROJECT_URL_MARKETPLACE": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`Swagger should match a snapshot 1`] = `
<SwaggerUI
docExpansion="none"
onComplete={[Function]}
requestInterceptor={[Function]}
/>
</div>
<Component
Expand Down
29 changes: 28 additions & 1 deletion packages/marketplace/src/components/pages/__tests__/swagger.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
import * as React from 'react'
import { shallow } from 'enzyme'

import Swagger, { handleOnComplete } from '../swagger'
import Swagger, { handleOnComplete, fetchInterceptor } from '../swagger'

jest.mock('../../../core/store')

describe('Swagger', () => {
it('should match a snapshot', () => {
expect(shallow(<Swagger />)).toMatchSnapshot()
})

it('should have a fetchInterceptor that adds a token when the url is not swagger', async () => {
process.env.SWAGGER_BASE_URL = 'https://some-url.com'
const request = {
url: 'https://some-other-url.com',
}
const result = await fetchInterceptor(request)
const output = {
...request,
headers: {
'Content-Type': 'application/json',
'api-version': 'latest',
Authorization: 'Bearer null',
},
}
expect(result).toEqual(output)
})

it('should have a fetchInterceptor that returns the params when the url is swagger', async () => {
process.env.SWAGGER_BASE_URL = 'https://some-url.com'
const request = {
url: process.env.SWAGGER_BASE_URL,
}
const result = await fetchInterceptor(request)
expect(result).toEqual(request)
})

it('handleOnComplete', () => {
const setLoading = jest.fn()
const fn = handleOnComplete(setLoading)
Expand Down
23 changes: 22 additions & 1 deletion packages/marketplace/src/components/pages/swagger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@ import '../../styles/vendor/swagger.scss'
import ErrorBoundary from '@/components/hocs/error-boundary'
import { Loader } from '@reapit/elements'
import { SandboxPopUp } from '../ui/sandbox-pop-up'
import { getAccessToken } from '@/utils/session'
import { StringMap } from '../../types/core'

export const handleOnComplete = setLoading => () => setLoading(false)

export const fetchInterceptor = async (params: StringMap) => {
if (params.url === process.env.SWAGGER_BASE_URL) {
return params
}
return {
...params,
headers: {
'Content-Type': 'application/json',
'api-version': 'latest',
Authorization: `Bearer ${await getAccessToken()}`,
},
}
}

export const SwaggerPage: React.SFC = () => {
const [loading, setLoading] = React.useState(true)

Expand All @@ -16,7 +32,12 @@ export const SwaggerPage: React.SFC = () => {
<div className="swagger">
{loading && <Loader />}
<div className={`${loading ? 'swagger-loading' : ''}`}>
<SwaggerUI url={process.env.SWAGGER_BASE_URL} onComplete={handleOnComplete(setLoading)} docExpansion="none" />
<SwaggerUI
url={process.env.SWAGGER_BASE_URL}
onComplete={handleOnComplete(setLoading)}
docExpansion="none"
requestInterceptor={fetchInterceptor}
/>
</div>
<SandboxPopUp loading={loading} />
</div>
Expand Down