mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-05 03:30:05 +00:00
fix: move function, test: added test for folder operations
This commit is contained in:
@@ -1328,20 +1328,22 @@ export class SASViyaApiClient {
|
||||
targetParentFolder,
|
||||
accessToken
|
||||
)
|
||||
targetFolderName = targetFolderDetails ? sourceFolderName : targetFolderName
|
||||
|
||||
if (!targetFolderDetails) {
|
||||
let targetParentFolderArr = targetParentFolder.split('/')
|
||||
targetParentFolderArr.splice(targetParentFolderArr.length - 1, 1)
|
||||
targetParentFolder = targetParentFolderArr.join('/')
|
||||
} else {
|
||||
targetFolderName = sourceFolderName
|
||||
}
|
||||
|
||||
// checks if 'sourceFolder' is already a URI
|
||||
const sourceFolderUri = isUri(sourceFolder)
|
||||
? sourceFolder
|
||||
: await this.getFolderUri(sourceFolder, accessToken)
|
||||
const sourceFolderUri = await this.getFolderUri(sourceFolder, accessToken)
|
||||
|
||||
// checks if 'targetParentFolder' is already a URI
|
||||
const targetParentFolderUri = isUri(targetParentFolder)
|
||||
? targetParentFolder
|
||||
: await this.getFolderUri(targetParentFolder, accessToken)
|
||||
const targetParentFolderUri = await this.getFolderUri(targetParentFolder, accessToken)
|
||||
|
||||
const sourceFolderId = sourceFolderUri?.split('/').pop()
|
||||
const url = sourceFolderUri
|
||||
|
||||
const requestInfo = {
|
||||
method: 'PATCH',
|
||||
@@ -1357,7 +1359,7 @@ export class SASViyaApiClient {
|
||||
}
|
||||
|
||||
const { result: folder } = await this.request<Folder>(
|
||||
`${this.serverUrl}${url}`,
|
||||
`${this.serverUrl}${sourceFolderUri}`,
|
||||
requestInfo
|
||||
).catch((err) => {
|
||||
if (err.code && err.code === 'ENOTFOUND') {
|
||||
|
||||
54
src/test/FolderOperations.spec.ts
Normal file
54
src/test/FolderOperations.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { SASViyaApiClient } from '../SASViyaApiClient'
|
||||
|
||||
const sampleResponse = `{
|
||||
"creationTimeStamp": "2021-01-06T14:09:27.705Z",
|
||||
"modifiedTimeStamp": "2021-01-06T14:46:57.391Z",
|
||||
"createdBy": "dctestuser1",
|
||||
"modifiedBy": "dctestuser1",
|
||||
"id": "00000-00000-00000-00000-00000",
|
||||
"name": "test",
|
||||
"parentFolderUri":"/folders/folders/00000-00000-00000-00000-00000",
|
||||
"type": "folder",
|
||||
"memberCount":"1"
|
||||
}`
|
||||
|
||||
describe('FolderOperations', () => {
|
||||
let originalFetch: any
|
||||
|
||||
const sasViyaApiClient = new SASViyaApiClient(
|
||||
'https://sample.server.com',
|
||||
'/Public',
|
||||
'Context',
|
||||
function() {}
|
||||
)
|
||||
|
||||
beforeAll(() => {
|
||||
originalFetch = (global as any).fetch
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
;(global as any).fetch = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
text: () => Promise.resolve(sampleResponse),
|
||||
json: () => Promise.resolve(sampleResponse),
|
||||
ok: true,
|
||||
headers: {
|
||||
get: function() { return '' }
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
;(global as any).fetch = originalFetch
|
||||
})
|
||||
|
||||
it('should move folder successfully', async (done) => {
|
||||
let res: any = await sasViyaApiClient.moveFolder('/Test/test', '/Test/toFolder', 'toFolder', 'token')
|
||||
|
||||
expect(JSON.stringify(res)).toEqual(
|
||||
JSON.stringify(sampleResponse)
|
||||
)
|
||||
done()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user