-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #SB-16923 merge: Merge pull request #219 from balakrishna10/rel…
…ease-2.7.0 Issue #SB-16923 feat: SDK changes for content sharing
- Loading branch information
Showing
6 changed files
with
157 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { CopyToDestination } from './copy-to-destination'; | ||
import {FileService} from '../../../util/file/def/file-service'; | ||
import {ContentEntry} from '../../db/schema'; | ||
import {Response} from '../../../api' | ||
|
||
describe('CopyToDestination', () => { | ||
let copyToDestination: CopyToDestination; | ||
const mockFileService: Partial<FileService> = {}; | ||
|
||
beforeAll(() => { | ||
copyToDestination = new CopyToDestination(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should be create a instance of copy asset', () => { | ||
expect(copyToDestination).toBeTruthy(); | ||
}); | ||
|
||
it('should be copied a file by invoked exicute() for error MEssage', async (done) => { | ||
// arrange | ||
const contentEntrySchema: ContentEntry.SchemaMap[] = [{ | ||
identifier: 'IDENTIFIER', | ||
server_data: 'SERVER_DATA', | ||
local_data: '{"children": [{"DOWNLOAD": 1}, "do_234", "do_345"], "artifactUrl": "http:///do_123"}', | ||
mime_type: 'MIME_TYPE', | ||
manifest_version: 'MAINFEST_VERSION', | ||
content_type: 'CONTENT_TYPE', | ||
content_state: 2, | ||
}]; | ||
|
||
const exportContext = { | ||
destinationFolder: 'SAMPLE_DESTINATION_FOLDER', | ||
tmpLocationPath: 'SAMPLE_TEMP_PATH', | ||
contentModelsToExport: contentEntrySchema, | ||
items: ['artifactUrl'], | ||
metadata: {'SAMPLE_KEY': 'SAMPLE_META_DATA'}, | ||
ecarFilePath: 'sampledir/samplefile' | ||
}; | ||
const response: Response = new Response(); | ||
|
||
response.body = exportContext; | ||
// act | ||
await copyToDestination.execute(response, 'SAMPLE_DESTINATION_FOLDER').then((result) => { | ||
// assert | ||
expect(result).toEqual(response); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should be copied a file by invoked exicute() for error MEssage', async (done) => { | ||
// arrange | ||
const contentEntrySchema: ContentEntry.SchemaMap[] = [{ | ||
identifier: 'IDENTIFIER', | ||
server_data: 'SERVER_DATA', | ||
local_data: '{"children": [{"DOWNLOAD": 1}, "do_234", "do_345"], "artifactUrl": "http:///do_123"}', | ||
mime_type: 'MIME_TYPE', | ||
manifest_version: 'MAINFEST_VERSION', | ||
content_type: 'CONTENT_TYPE', | ||
content_state: 2, | ||
}]; | ||
|
||
const exportContext = { | ||
destinationFolder: 'SAMPLE_DESTINATION_FOLDER', | ||
tmpLocationPath: 'SAMPLE_TEMP_PATH', | ||
contentModelsToExport: contentEntrySchema, | ||
items: ['artifactUrl'], | ||
metadata: {'SAMPLE_KEY': 'SAMPLE_META_DATA'}, | ||
ecarFilePath: 'sampledir/samplefile' | ||
}; | ||
const response: Response = new Response(); | ||
|
||
response.body = exportContext; | ||
// act | ||
await copyToDestination.execute(response, 'SAMPLE_DESTINATION_FOLDER').catch((result) => { | ||
// assert | ||
done(); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Response } from '../../../api'; | ||
import {FileUtil} from '../../../util/file/util/file-util'; | ||
import { ContentExportRequest } from '../..'; | ||
|
||
export class CopyToDestination { | ||
|
||
constructor() { | ||
} | ||
|
||
public async execute(exportResponse: Response, contentExportRequest: ContentExportRequest): Promise<Response> { | ||
return new Promise<Response>((resolve, reject) => { | ||
let destinationFolder; | ||
if (contentExportRequest.saveLocally) { | ||
destinationFolder = contentExportRequest.destinationFolder; | ||
} else { | ||
destinationFolder = cordova.file.externalCacheDirectory; | ||
} | ||
buildconfigreader.copyFile(FileUtil.getDirecory(exportResponse.body.ecarFilePath), destinationFolder, | ||
FileUtil.getFileName(exportResponse.body.ecarFilePath), | ||
() => { | ||
resolve(exportResponse); | ||
}, err => { | ||
console.error(err); | ||
resolve(err); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {Response} from '../../../api'; | ||
import {ExportContentContext} from '../..'; | ||
|
||
export class DeleteTempDir { | ||
|
||
constructor() { | ||
} | ||
|
||
public async execute(exportContext: ExportContentContext): Promise<Response> { | ||
const response: Response = new Response(); | ||
return new Promise<Response>((resolve, reject) => { | ||
const tmpDirPath = exportContext.destinationFolder!.concat('tmp/'); | ||
buildconfigreader.rm(tmpDirPath, '', () => { | ||
response.body = exportContext; | ||
resolve(response); | ||
}, (e) => { | ||
response.body = exportContext; | ||
resolve(response); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters