mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-17 00:50:05 +00:00
test: fixing
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
|
import { RequestClient } from '../request/RequestClient'
|
||||||
import { SASViyaApiClient } from '../SASViyaApiClient'
|
import { SASViyaApiClient } from '../SASViyaApiClient'
|
||||||
|
import axios from 'axios'
|
||||||
|
jest.mock('axios')
|
||||||
|
const mockedAxios = axios as jest.Mocked<typeof axios>
|
||||||
|
|
||||||
describe('FolderOperations', () => {
|
describe('FolderOperations', () => {
|
||||||
let originalFetch: any
|
let originalFetch: any
|
||||||
@@ -7,19 +11,11 @@ describe('FolderOperations', () => {
|
|||||||
'https://sample.server.com',
|
'https://sample.server.com',
|
||||||
'/Public',
|
'/Public',
|
||||||
'Context',
|
'Context',
|
||||||
function () {}
|
new RequestClient('https://sample.server.com')
|
||||||
)
|
)
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
originalFetch = (global as any).fetch
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(() => {})
|
beforeEach(() => {})
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
;(global as any).fetch = originalFetch
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should move and rename folder', async (done) => {
|
it('should move and rename folder', async (done) => {
|
||||||
mockFetchResponse(false)
|
mockFetchResponse(false)
|
||||||
|
|
||||||
@@ -30,10 +26,10 @@ describe('FolderOperations', () => {
|
|||||||
'token'
|
'token'
|
||||||
)
|
)
|
||||||
|
|
||||||
let jsonResponse = JSON.parse(res)
|
console.log(`[res]`, res)
|
||||||
|
|
||||||
expect(jsonResponse.name).toEqual('newName')
|
expect(res.folder.name).toEqual('newName')
|
||||||
expect(jsonResponse.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
expect(res.folder.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
@@ -48,10 +44,8 @@ describe('FolderOperations', () => {
|
|||||||
'token'
|
'token'
|
||||||
)
|
)
|
||||||
|
|
||||||
let jsonResponse = JSON.parse(res)
|
expect(res.folder.name).toEqual('oldName')
|
||||||
|
expect(res.folder.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
||||||
expect(jsonResponse.name).toEqual('oldName')
|
|
||||||
expect(jsonResponse.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
@@ -66,61 +60,29 @@ describe('FolderOperations', () => {
|
|||||||
'token'
|
'token'
|
||||||
)
|
)
|
||||||
|
|
||||||
let jsonResponse = JSON.parse(res)
|
expect(res.folder.name).toEqual('newName')
|
||||||
|
expect(res.folder.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
||||||
expect(jsonResponse.name).toEqual('newName')
|
|
||||||
expect(jsonResponse.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const mockFetchResponse = (targetFolderExists: boolean) => {
|
const mockFetchResponse = (targetFolderExists: boolean) => {
|
||||||
;(global as any).fetch = jest
|
mockedAxios.patch.mockImplementation((url: any, request: any) => {
|
||||||
.fn()
|
return Promise.resolve({status: 200, data: {folder: request}})
|
||||||
.mockImplementation((url: any, request: any) => {
|
})
|
||||||
console.log(`[url]`, url)
|
|
||||||
console.log(`[request]`, request)
|
|
||||||
|
|
||||||
if (
|
mockedAxios.get.mockImplementation((url: any, request: any) => {
|
||||||
request.method === 'GET' &&
|
if (!targetFolderExists &&
|
||||||
!targetFolderExists &&
|
url.includes('newName')) {
|
||||||
url.includes('newName')
|
return Promise.resolve(undefined)
|
||||||
) {
|
}
|
||||||
return Promise.resolve({
|
|
||||||
text: () => Promise.resolve(undefined),
|
return Promise.resolve({
|
||||||
json: () => Promise.resolve(undefined),
|
status: 200,
|
||||||
ok: true,
|
data: {
|
||||||
headers: {
|
id: url
|
||||||
get: function () {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.method === 'GET' && url.includes('/Test/toFolder')) {
|
|
||||||
return Promise.resolve({
|
|
||||||
text: () => Promise.resolve({ id: url }),
|
|
||||||
json: () => Promise.resolve({ id: url }),
|
|
||||||
ok: true,
|
|
||||||
headers: {
|
|
||||||
get: function () {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve({
|
|
||||||
text: () => Promise.resolve(request.body),
|
|
||||||
json: () => Promise.resolve(request.body),
|
|
||||||
ok: true,
|
|
||||||
headers: {
|
|
||||||
get: function () {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user