Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed Mar 31, 2023
1 parent 864d567 commit db28217
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/javascript/src/ActiveDocs/ThreeScaleApiDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ type BodyValue = boolean | number | string | { [key: string]: BodyValue }
* }
* @param object
*/
export const objectToFormData = (object: BodyValue): Record<string, string> => {
const buildFormData = (formData: Record<string, string>, data: BodyValue, parentKey?: string) => {
export const objectToFormData = (object: BodyValue): Record<string, boolean | number | string> => {
const buildFormData = (formData: Record<string, boolean | number | string>, data: BodyValue, parentKey?: string) => {
if (data && typeof data === 'object') {
Object.keys(data).forEach((key: string) => {
buildFormData(formData, data[key], parentKey ? `${parentKey}[${key}]` : key)
})
} else {
if (parentKey) {
formData[parentKey] = data ? encodeURIComponent(data) : ''
formData[parentKey] = data ? data : ''
}
}
}
Expand All @@ -74,7 +74,7 @@ export const objectToFormData = (object: BodyValue): Record<string, string> => {
* 'transactions[0][usage][hits]': 1
* @param body BackendApiReportBody
*/
export const transformReportRequestBody = (body: BackendApiReportBody): Record<string, string> => {
export const transformReportRequestBody = (body: BackendApiReportBody): Record<string, boolean | number | string> => {
if (Array.isArray(body.transactions)) {
body.transactions = body.transactions.map(transaction => {
switch (typeof transaction) {
Expand Down
2 changes: 0 additions & 2 deletions app/javascript/src/Types/SwaggerTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,3 @@ export interface BackendApiReportBody {
service_id?: string;
transactions?: (BackendApiTransaction | string)[];
}

export type BackendApiReportFormData = Record<string, string>
3 changes: 3 additions & 0 deletions app/javascript/src/Types/swagger.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'swagger-client/es/execute' {
export function execute (req: unknown): unknown
}
3 changes: 1 addition & 2 deletions spec/javascripts/ActiveDocs/ThreeScaleApiDocs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ const body: BackendApiReportBody = {
]
}

describe('transformRequestBody', () => {
describe('transformReportRequestBody', () => {
it('transforms the transactions array when transaction is an object', () => {
const result = transformReportRequestBody(body)

console.log(result)
expect(result).toEqual({
service_token: 'token',
service_id: '123',
Expand Down
5 changes: 5 additions & 0 deletions spec/javascripts/__mocks__/swagger-client/es/execute/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
execute: {
create: () => jest.fn()
}
}

0 comments on commit db28217

Please sign in to comment.