Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add version to copy file options annotation #885

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,12 @@ target folder.
client.files.copy('12345', '0', {name: 'Renamed file.png'}, callback);
```

You can specify specific file version to copy by passing optional `version` parameter.

```js
client.files.copy('12345', '0', {version: '1'}, callback);
```

## Delete a File

Calling the
Expand Down
4 changes: 3 additions & 1 deletion src/managers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import httpStatusCodes from 'http-status';
import { Readable, Writable } from 'stream';
import urlTemplate from 'url-template';
import BoxClient from '../box-client';
import * as schemas from "../schemas";
import errors from '../util/errors';
import urlPath from '../util/url-path';
import * as schemas from "../schemas";

const ChunkedUploader = require('../chunked-uploader');

Expand Down Expand Up @@ -512,6 +512,7 @@ class Files {
* @param {string} newParentID - The Box ID for the new parent folder. '0' to copy to All Files.
* @param {Object} [options] - Optional parameters for the copy operation, can be left null in most cases
* @param {string} [options.name] - A new name to use if there is an identically-named item in the new parent folder
* @param {string} [options.version] - An optional ID of the specific file version to copy
* @param {Function} [callback] - passed the new file info if call was successful
* @returns {Promise<Object>} A promise resolving to the new file object
*/
Expand All @@ -521,6 +522,7 @@ class Files {
options?:
| {
name?: string;
version?: string;
}
| Function,
callback?: Function
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/managers/files-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,13 +783,15 @@ describe('Files', function() {
it('should make POST request to copy the folder with optional parameters when passed', function() {

var name = 'rename on copy';
var version = '1';

expectedParams.body.name = name;
expectedParams.body.version = version;

sandbox.stub(boxClientFake, 'wrapWithDefaultHandler').returnsArg(0);
sandbox.mock(boxClientFake).expects('post')
.withArgs('/files/1234/copy', expectedParams);
files.copy(FILE_ID, NEW_PARENT_ID, {name});
files.copy(FILE_ID, NEW_PARENT_ID, {name, version});
});

it('should wrap with default handler when called', function() {
Expand Down
Loading