mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-17 00:50:05 +00:00
fix(form-data): fixed formData type check
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import * as NodeFormData from 'form-data'
|
import * as NodeFormData from 'form-data'
|
||||||
import { convertToCSV } from '../utils/convertToCsv'
|
import { convertToCSV } from '../utils/convertToCsv'
|
||||||
|
import { isNode } from '../utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One of the approaches SASjs takes to send tables-formatted JSON (see README)
|
* One of the approaches SASjs takes to send tables-formatted JSON (see README)
|
||||||
@@ -26,12 +27,14 @@ export const generateFileUploadForm = (
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formData instanceof NodeFormData) {
|
if (isNode()) {
|
||||||
formData.append(name, csv, {
|
// environment is Node and formData is instance of NodeFormData
|
||||||
|
;(formData as NodeFormData).append(name, csv, {
|
||||||
filename: `${name}.csv`,
|
filename: `${name}.csv`,
|
||||||
contentType: 'application/csv'
|
contentType: 'application/csv'
|
||||||
})
|
})
|
||||||
} else if (formData instanceof FormData) {
|
} else {
|
||||||
|
// environment is Browser and formData is instance of FormData
|
||||||
const file = new Blob([csv], {
|
const file = new Blob([csv], {
|
||||||
type: 'application/csv'
|
type: 'application/csv'
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { generateFileUploadForm } from '../generateFileUploadForm'
|
import { generateFileUploadForm } from '../generateFileUploadForm'
|
||||||
import * as NodeFormData from 'form-data'
|
|
||||||
import { convertToCSV } from '../../utils/convertToCsv'
|
import { convertToCSV } from '../../utils/convertToCsv'
|
||||||
|
import * as NodeFormData from 'form-data'
|
||||||
|
import * as isNodeModule from '../../utils/isNode'
|
||||||
|
|
||||||
describe('generateFileUploadForm', () => {
|
describe('generateFileUploadForm', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
@@ -14,6 +15,10 @@ describe('generateFileUploadForm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('browser', () => {
|
describe('browser', () => {
|
||||||
|
afterAll(() => {
|
||||||
|
jest.restoreAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
it('should generate file upload form from data', () => {
|
it('should generate file upload form from data', () => {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
const testTable = 'sometable'
|
const testTable = 'sometable'
|
||||||
@@ -33,6 +38,7 @@ describe('generateFileUploadForm', () => {
|
|||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
jest.spyOn(formData, 'append').mockImplementation(() => {})
|
jest.spyOn(formData, 'append').mockImplementation(() => {})
|
||||||
|
jest.spyOn(isNodeModule, 'isNode').mockImplementation(() => false)
|
||||||
|
|
||||||
generateFileUploadForm(formData, testTableWithNullVars)
|
generateFileUploadForm(formData, testTableWithNullVars)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user