-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
158 additions
and
3 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
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,44 @@ | ||
const request = require('./request'); | ||
|
||
const { API_RESOURCES_URL } = require('./constants'); | ||
|
||
/** | ||
* Create Folder | ||
* @see https://tech.yandex.com/disk/api/reference/create-folder-docpage/ | ||
* @param {string} token OAuth token | ||
* @param {string} [path] Path | ||
* @param {function} [success] Success callback | ||
* @param {function} [error] Error callback | ||
*/ | ||
const create = (token, path, success, error) => | ||
request.put({ | ||
url: API_RESOURCES_URL, | ||
token: token, | ||
query: { | ||
path: path | ||
} | ||
}, success, error); | ||
|
||
/** | ||
* Remove File or Folder | ||
* @see https://tech.yandex.com/disk/api/reference/delete-docpage/ | ||
* @param {string} token OAuth token | ||
* @param {string} [path] File or Folder Path | ||
* @param {boolean} [permanently] permanently default false | ||
* @param {function} [success] Success callback | ||
* @param {function} [error] Error callback | ||
*/ | ||
const remove = (token, path, permanently=false, success, error) => | ||
request.delete({ | ||
url: API_RESOURCES_URL, | ||
token: token, | ||
query: { | ||
path: path, | ||
permanently: permanently | ||
} | ||
}, success, error); | ||
|
||
module.exports = { | ||
create, | ||
remove | ||
}; |
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 |
---|---|---|
|
@@ -9,7 +9,8 @@ | |
}, | ||
"author": "Roman Charugin <[email protected]> (https://github.com/RomiC)", | ||
"contributors": [ | ||
"Roman Charugin <[email protected]> (https://github.com/RomiC)" | ||
"Roman Charugin <[email protected]> (https://github.com/RomiC)", | ||
"Mustafa Yazar <[email protected]> (https://github.com/myazarc)" | ||
], | ||
"license": "MIT", | ||
"engines": { | ||
|
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
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,50 @@ | ||
import { mock } from 'sinon'; | ||
import test from 'ava'; | ||
|
||
import request from '../lib/request'; | ||
import {create,remove} from '../lib/resources'; | ||
|
||
import { API_TOKEN } from './constants'; | ||
import { API_RESOURCES_URL } from '../lib/constants'; | ||
|
||
const folderName='disk:/folderName'; | ||
const permanently=true; | ||
|
||
test('create folder', (t) => { | ||
const requestMock = mock(request); | ||
|
||
requestMock.expects('put').once().withArgs({ | ||
url: API_RESOURCES_URL, | ||
token: API_TOKEN, | ||
query: { | ||
path: folderName | ||
} | ||
}); | ||
|
||
create(API_TOKEN,folderName); | ||
|
||
requestMock.verify(); | ||
requestMock.restore(); | ||
|
||
t.pass(); | ||
}); | ||
|
||
test('remove folder or file', (t) => { | ||
const requestMock = mock(request); | ||
|
||
requestMock.expects('delete').once().withArgs({ | ||
url: API_RESOURCES_URL, | ||
token: API_TOKEN, | ||
query: { | ||
path: folderName, | ||
permanently: permanently | ||
} | ||
}); | ||
|
||
remove(API_TOKEN,folderName,permanently); | ||
|
||
requestMock.verify(); | ||
requestMock.restore(); | ||
|
||
t.pass(); | ||
}); |