mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-15 08:00: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,
|
targetParentFolder,
|
||||||
accessToken
|
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
|
// checks if 'sourceFolder' is already a URI
|
||||||
const sourceFolderUri = isUri(sourceFolder)
|
const sourceFolderUri = await this.getFolderUri(sourceFolder, accessToken)
|
||||||
? sourceFolder
|
|
||||||
: await this.getFolderUri(sourceFolder, accessToken)
|
|
||||||
|
|
||||||
// checks if 'targetParentFolder' is already a URI
|
// checks if 'targetParentFolder' is already a URI
|
||||||
const targetParentFolderUri = isUri(targetParentFolder)
|
const targetParentFolderUri = await this.getFolderUri(targetParentFolder, accessToken)
|
||||||
? targetParentFolder
|
|
||||||
: await this.getFolderUri(targetParentFolder, accessToken)
|
|
||||||
|
|
||||||
const sourceFolderId = sourceFolderUri?.split('/').pop()
|
const sourceFolderId = sourceFolderUri?.split('/').pop()
|
||||||
const url = sourceFolderUri
|
|
||||||
|
|
||||||
const requestInfo = {
|
const requestInfo = {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
@@ -1357,7 +1359,7 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { result: folder } = await this.request<Folder>(
|
const { result: folder } = await this.request<Folder>(
|
||||||
`${this.serverUrl}${url}`,
|
`${this.serverUrl}${sourceFolderUri}`,
|
||||||
requestInfo
|
requestInfo
|
||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
if (err.code && err.code === 'ENOTFOUND') {
|
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