|
@@ -3,72 +3,87 @@ import nock from 'nock'
|
|
|
import Utils from '../../src/core/Utils'
|
|
|
import Google from '../../src/plugins/GoogleDrive'
|
|
|
|
|
|
-test('checkAuthentication success', function (t) {
|
|
|
- t.plan(1)
|
|
|
+var defaultCore = {
|
|
|
+ state: {
|
|
|
+ googleDrive: {
|
|
|
+ authenticated: false,
|
|
|
+ files: [],
|
|
|
+ folders: [],
|
|
|
+ directory: 'root'
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+test('checkAuthentication success', function (t) {
|
|
|
nock('http://localhost:3020')
|
|
|
.get('/google/authorize')
|
|
|
.reply(200, {
|
|
|
isAuthenticated: true
|
|
|
})
|
|
|
|
|
|
- var GoogleDrive = new Google(null, {host: 'http://localhost:3020'})
|
|
|
+ var core = Object.assign({}, defaultCore)
|
|
|
+
|
|
|
+ var GoogleDrive = new Google(core, {host: 'http://localhost:3020'})
|
|
|
+
|
|
|
GoogleDrive.checkAuthentication()
|
|
|
.then((isAuthed) => {
|
|
|
t.equal(isAuthed, true)
|
|
|
+ t.end()
|
|
|
})
|
|
|
})
|
|
|
|
|
|
test('checkAuthentication fail', function (t) {
|
|
|
- t.plan(1)
|
|
|
-
|
|
|
nock('http://localhost:3020')
|
|
|
.get('/google/authorize')
|
|
|
.reply(200, {
|
|
|
isAuthenticated: false
|
|
|
})
|
|
|
|
|
|
- var GoogleDrive = new Google(null, {host: 'http://localhost:3020'})
|
|
|
+ var core = Object.assign({}, defaultCore)
|
|
|
+
|
|
|
+ var GoogleDrive = new Google(core, {host: 'http://localhost:3020'})
|
|
|
+
|
|
|
GoogleDrive.checkAuthentication()
|
|
|
.then((isAuthed) => {
|
|
|
t.equal(isAuthed, false)
|
|
|
+ t.end()
|
|
|
})
|
|
|
})
|
|
|
|
|
|
test('getFile: success', function (t) {
|
|
|
- t.plan(1)
|
|
|
-
|
|
|
nock('http://localhost:3020')
|
|
|
- .post('/google/get')
|
|
|
- .reply(201, (uri, requestBody) => {
|
|
|
- return {
|
|
|
- ok: true,
|
|
|
- id: '12345'
|
|
|
- }
|
|
|
+ .get('/google/get?fileId=12345')
|
|
|
+ .reply(201, {
|
|
|
+ ok: true,
|
|
|
+ id: '12345'
|
|
|
})
|
|
|
|
|
|
- var GoogleDrive = new Google(null, {host: 'http://localhost:3020'})
|
|
|
+ var core = Object.assign({}, defaultCore)
|
|
|
+
|
|
|
+ var GoogleDrive = new Google(core, {host: 'http://localhost:3020'})
|
|
|
|
|
|
GoogleDrive.getFile('12345')
|
|
|
.then((result) => {
|
|
|
t.equal(result.ok, true)
|
|
|
+ t.end()
|
|
|
})
|
|
|
})
|
|
|
|
|
|
test('getFile: fileId not a string', function (t) {
|
|
|
- t.plan(1)
|
|
|
+ var core = Object.assign({}, defaultCore)
|
|
|
+
|
|
|
+ var GoogleDrive = new Google(core, {host: 'http://localhost:3020'})
|
|
|
|
|
|
- var GoogleDrive = new Google(null, {host: 'http://localhost:3020'})
|
|
|
var result = GoogleDrive.getFile()
|
|
|
|
|
|
t.equal(result instanceof Error, true)
|
|
|
+
|
|
|
+ t.end()
|
|
|
})
|
|
|
|
|
|
test('getFolder: success', function (t) {
|
|
|
- t.plan(1)
|
|
|
-
|
|
|
nock('http://localhost:3020')
|
|
|
- .get('/google/list')
|
|
|
+ .get('/google/list?dir=root')
|
|
|
.reply(200, {
|
|
|
items: [{
|
|
|
mimeType: 'application/vnd.google-apps.folder'
|
|
@@ -81,8 +96,11 @@ test('getFolder: success', function (t) {
|
|
|
}]
|
|
|
})
|
|
|
|
|
|
- var GoogleDrive = new Google(null, {host: 'http://localhost:3020'})
|
|
|
- GoogleDrive.getFolder('/')
|
|
|
+ var core = Object.assign({}, defaultCore)
|
|
|
+
|
|
|
+ var GoogleDrive = new Google(core, {host: 'http://localhost:3020'})
|
|
|
+
|
|
|
+ GoogleDrive.getFolder('root')
|
|
|
.then((res) => {
|
|
|
const allFolders = Utils.every(res.folders, function (folder) {
|
|
|
return folder.mimeType === 'application/vnd.google-apps.folder'
|
|
@@ -93,19 +111,22 @@ test('getFolder: success', function (t) {
|
|
|
})
|
|
|
|
|
|
t.equal(allFolders && allFiles, true)
|
|
|
+ t.end()
|
|
|
})
|
|
|
})
|
|
|
|
|
|
test('getFolder: fail', function (t) {
|
|
|
- t.plan(1)
|
|
|
-
|
|
|
nock('http://localhost:3020')
|
|
|
.get('/google/list')
|
|
|
.reply(500, 'Not authenticated')
|
|
|
|
|
|
- var GoogleDrive = new Google(null, {host: 'http://localhost:3020'})
|
|
|
+ var core = Object.assign({}, defaultCore)
|
|
|
+
|
|
|
+ var GoogleDrive = new Google(core, {host: 'http://localhost:3020'})
|
|
|
+
|
|
|
GoogleDrive.getFolder('/')
|
|
|
.then((err) => {
|
|
|
t.equal(err instanceof Error, true)
|
|
|
+ t.end()
|
|
|
})
|
|
|
})
|