-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
a2852e9
commit 7763c48
Showing
6 changed files
with
158 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const test = require('tape'); | ||
const tryToCatch = require('try-to-catch'); | ||
const sinon = require('sinon'); | ||
|
||
const operate = require('./operate'); | ||
|
||
const reject = Promise.reject.bind(Promise); | ||
|
||
test('restbox: operate', async (t) => { | ||
const copy = sinon | ||
.stub() | ||
.returns(reject(Error('error'))); | ||
|
||
const [e] = await tryToCatch(operate, copy, 'token', 'dir', [ | ||
'1.txt' | ||
]); | ||
|
||
t.equal(e.message, 'error', 'should equal'); | ||
t.end(); | ||
}); |
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,99 @@ | ||
'use strict'; | ||
|
||
const calledWithDiff = require('sinon-called-with-diff'); | ||
const sinon = calledWithDiff(require('sinon')); | ||
const test = require('tape'); | ||
|
||
const mockRequire = require('mock-require'); | ||
const {reRequire} = mockRequire; | ||
|
||
const restbox = require('../restbox'); | ||
const {request} = require('serve-once')(restbox); | ||
|
||
const pathPut = './move'; | ||
const pathRestbox = '../restbox'; | ||
|
||
test('restbox: move: no token', async (t) => { | ||
const {body} = await request.put('/dropbox/mv', { | ||
body: { | ||
from: '/', | ||
to: '/tmp', | ||
names: ['1.txt'], | ||
} | ||
}); | ||
|
||
t.equal(body, 'token should be a string!', 'should return error message'); | ||
t.end(); | ||
}); | ||
|
||
test('restbox: move', async (t) => { | ||
const operate = sinon | ||
.stub() | ||
.returns(Promise.resolve()); | ||
|
||
mockRequire('./common/operate', operate); | ||
|
||
reRequire(pathPut); | ||
const restbox = reRequire(pathRestbox); | ||
const {request} = reRequire('serve-once')(restbox); | ||
const {move} = require('@cloudcmd/dropbox'); | ||
|
||
const token = 'hello' | ||
const options = { | ||
token, | ||
}; | ||
|
||
const names = [ | ||
'1.txs', | ||
]; | ||
|
||
const files = { | ||
from: '/', | ||
to: '/tmp', | ||
names, | ||
}; | ||
|
||
await request.put('/dropbox/mv', { | ||
body: files, | ||
options, | ||
}); | ||
|
||
t.ok(operate.calledWith(move, token, '/', '/tmp', names), 'should call mkdir with token'); | ||
t.end(); | ||
}); | ||
|
||
test('restbox: move: response', async (t) => { | ||
const operate = sinon | ||
.stub() | ||
.returns(Promise.resolve()); | ||
|
||
mockRequire('./common/operate', operate); | ||
|
||
reRequire(pathPut); | ||
const restbox = reRequire(pathRestbox); | ||
const {request} = reRequire('serve-once')(restbox); | ||
|
||
const token = 'hello' | ||
const options = { | ||
token, | ||
}; | ||
|
||
const names = [ | ||
'1.txt', | ||
]; | ||
|
||
const files = { | ||
from: '/', | ||
to: '/tmp', | ||
names, | ||
}; | ||
|
||
const {body} = await request.put('/dropbox/mv', { | ||
body: files, | ||
options, | ||
}); | ||
|
||
t.equal(body, 'move: ok("1.txt")', 'should equal'); | ||
t.end(); | ||
}); | ||
|
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 @@ | ||
'use strict'; | ||
|
||
const {promisify} = require('util'); | ||
|
||
const express = require('express'); | ||
const http = require('http'); | ||
|
||
const restbox = require('./restbox'); | ||
const fetch = require('node-fetch'); | ||
const {serve} = require('serve-once')(restbox); | ||
|
||
const tryToCatch = require('try-to-catch'); | ||
const currify = require('currify'); | ||
|
||
const tryToTape = require('try-to-tape'); | ||
const test = tryToTape(require('tape')); | ||
|
||
test('restbox: no options', async (t) => { | ||
const {port, close} = await serve(); | ||
const response = await fetch(`http://localhost:${port}/dropbox/fs/`); | ||
const result = await response.text(); | ||
|
||
await close(); | ||
|
||
t.equal(result, 'token should be a string!', 'should equal'); | ||
t.end(); | ||
}); | ||
|