UNPKG

gsweet

Version:

Help with writing scripts to run against gSuite

177 lines (140 loc) 6.73 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: drive/driveOps.test.int.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: drive/driveOps.test.int.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/** * @module drive/driveOps Integration Tests */ const chai = require('chai') const should = chai.should() const Gsweet = require('../main') const logger = require('../utils/logger') const testData = require('../test-data/integration') const testDrive = testData.drive const NO_FILES = 'a long name that should n-o-t exist in google drive' const UNTITLED_SPREADSHEET = testDrive.untitledSheet const COMMON_PART_NAME = testDrive.nameContainedMaxFilesTimes const MIN_GOOGLE_ID_LENGTH = 10 const MAX_FILES_PER_QUERY = 1000 const gsweet = new Gsweet({pathOrVarName:'/Users/tod-gentille/dev/node/ENV_VARS/gsweet.env.json', useExistingEnvVar:false}) const {driveOps} = gsweet before(() => {logger.level = 'info'}) after(() => {logger.level = 'debug'}) describe('INTEGRATION TEST driveOps module', function () { this.timeout(10000) const {mimeType} = driveOps const FOLDER_TYPE = mimeType.getType(mimeType.FOLDER) const SPREADSHEET_TYPE = mimeType.getType(mimeType.SPREADSHEET) it('fileList() should return MAX_FILES_PER_QUERY files', async () => { const fileList = await driveOps.listFiles() fileList.length.should.equal(MAX_FILES_PER_QUERY) }) describe('getFiles() should', () => { it('return multiple UNTITLED_SPREADSHEET files', async () => { const files = await driveOps.getFiles({withName: UNTITLED_SPREADSHEET}) files.length.should.be.gt(1) }) it('return the MAX_FILES_PER_QUERY for PLURALSIGHT_FILES', async () => { const files = await driveOps.getFiles({withName: COMMON_PART_NAME, exactMatch: false}) files.length.should.equal(MAX_FILES_PER_QUERY) }) }) describe('getFileId({withName}) should', () => { it('get the TEST_FILE id', async () => { const id = await driveOps.getFileId({withName: testDrive.sheetFile}) id.length.should.be.gt(MIN_GOOGLE_ID_LENGTH) }) }) describe('getFile({withName}) should', () => { it('should return the TEST_FILE id and name', async () => { const file = await driveOps.getFile({withName: testDrive.sheetFile}) file.id.length.should.be.gt(MIN_GOOGLE_ID_LENGTH) file.name.length.should.equal(testDrive.sheetFile.length) }) it('reject when no files are found', async () => { await driveOps.getFile({withName: NO_FILES}) .catch(error => { error.should.contain('Found 0 files') }) }) it('reject when multiple files are found', async () => { await driveOps.getFile({withName: UNTITLED_SPREADSHEET}) .catch(error => { error.should.match(/Found \d+ files.*/) }) }) }) describe('getFilesInFolder() should', () => { it('return some files in testDrive.folderId', async () => { const folderOptions = {withFolderId: testDrive.folderId} const files = await driveOps.getFilesInFolder(folderOptions) files.length.should.be.above(0) }) it('find just files (not folders)', async () => { const folderOptions = {withFolderId: testDrive.folderId, ofType: mimeType.FILE} const files = await driveOps.getFilesInFolder(folderOptions) files.forEach(entry => { entry.mimeType.should.not.equal(FOLDER_TYPE) }) }) it('find just spreadsheets', async () => { const folderOptions = {withFolderId: testDrive.folderId, ofType: mimeType.SPREADSHEET} const files = await driveOps.getFilesInFolder(folderOptions) files.forEach(entry => { entry.mimeType.should.equal(SPREADSHEET_TYPE) }) }) }) describe('GetFileNamesInFolder() should', () => { it('return just the names', async () => { const names = await driveOps.getFileNamesInFolder({withFolderId: testDrive.folderId}) Array.isArray(names).should.be.true }) }) describe('GetFilesRecursively() should', () => { it('find files at root and subfolder ', async () => { const files = await driveOps.getFilesRecursively({withFolderId: testDrive.folderId}) files.find(e => e.name === testDrive.subfolder).should.not.be.undefined files.find(e => e.name === testDrive.sheetFile).should.not.be.undefined files.find(e => e.name === testDrive.docFile).should.not.be.undefined files.find(e => e.name === testDrive.subfolderSheet).should.not.be.undefined files.find(e => e.name === testDrive.subfolderDoc).should.not.be.undefined }) it('find spreadsheet files only at root and subfolder ', async () => { const files = await driveOps.getFilesRecursively({withFolderId: testDrive.folderId, ofType: mimeType.SPREADSHEET}) files.find(e => e.name === testDrive.subfolder).should.not.be.undefined files.find(e => e.name === testDrive.sheetFile).should.not.be.undefined files.find(e => e.name === testDrive.subfolderSheet).should.not.be.undefined should.not.exist(files.find(e => e.name === testDrive.docFile)) should.not.exist(files.find(e => e.name === testDrive.subfolderDoc)) }) }) })</code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="Drive_driveOps.module_test.html">test</a></li><li><a href="module-drive_driveOps.html">drive/driveOps</a></li><li><a href="module-Drive_driveOps%2520Integration%2520Tests.html">Drive/driveOps Integration Tests</a></li><li><a href="module-drive_driveService.html">drive/driveService</a></li><li><a href="module-Sheet_sheetOps%2520Integration%2520Tests.html">Sheet/sheetOps Integration Tests</a></li><li><a href="sheets_sheetOps.module_js.html">sheets/sheetOps.js</a></li><li><a href="sheets_sheetService.module_js.html">sheets/sheetService.js</a></li><li><a href="-_sheetOps.module_test.html">test</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 11 2019 23:52:27 GMT-0700 (Pacific Daylight Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>