123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import test from 'tape'
- import nock from 'nock'
- import Core from '../../src/core/Core'
- import Utils from '../../src/core/Utils'
- import Google from '../../src/plugins/GoogleDrive'
- 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 core = new Core()
- var GoogleDrive = new Google(core, {host: 'http://localhost:3020'})
- GoogleDrive.checkAuthentication()
- .then((isAuthed) => {
- t.equal(isAuthed, true)
- t.end()
- })
- })
- test('checkAuthentication fail', function (t) {
- nock('http://localhost:3020')
- .get('/google/authorize')
- .reply(200, {
- isAuthenticated: false
- })
- var core = new Core()
- var GoogleDrive = new Google(core, {host: 'http://localhost:3020'})
- GoogleDrive.checkAuthentication()
- .then((isAuthed) => {
- t.equal(isAuthed, false)
- t.end()
- })
- })
- test('getFile: success', function (t) {
- nock('http://localhost:3020')
- .get('/google/get?fileId=12345')
- .reply(201, {
- ok: true,
- id: '12345'
- })
- var core = new Core()
- 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) {
- var core = new Core()
- var GoogleDrive = new Google(core, {host: 'http://localhost:3020'})
- var result = GoogleDrive.getFile()
- t.equal(result instanceof Error, true)
- t.end()
- })
- test('getFolder: success', function (t) {
- nock('http://localhost:3020')
- .get('/google/list?dir=root')
- .reply(200, {
- items: [{
- mimeType: 'application/vnd.google-apps.folder'
- }, {
- mimeType: 'application/vnd.google-apps.spreadsheet'
- }, {
- mimeType: 'application/vnd.google-apps.spreadsheet'
- }, {
- mimeType: 'application/vnd.google-apps.folder'
- }]
- })
- var core = new Core()
- 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'
- })
- const allFiles = Utils.every(res.files, (file) => {
- return file.mimeType !== 'application/vnd.google-apps.folder'
- })
- t.equal(allFolders && allFiles, true)
- t.end()
- })
- })
- test('getFolder: fail', function (t) {
- nock('http://localhost:3020')
- .get('/google/list')
- .reply(500, 'Not authenticated')
- var core = new Core()
- var GoogleDrive = new Google(core, {host: 'http://localhost:3020'})
- GoogleDrive.getFolder('/')
- .then((err) => {
- t.equal(err instanceof Error, true)
- t.end()
- })
- })
|