Skip to content

Commit

Permalink
fix: add version to copy file options annotation (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda authored Aug 5, 2024
1 parent 658b761 commit 4f9312c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
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

0 comments on commit 4f9312c

Please sign in to comment.