Skip to content

Commit

Permalink
Add more tests (google#158)
Browse files Browse the repository at this point in the history
* Added more tests and un-skipped ones that can run without creds.

Also, noted that saveProjectId should be async or return a promise

Signed-off-by: campionfellin <[email protected]>

* Fix lint errors

Signed-off-by: campionfellin <[email protected]>

* Fix errors in PR 158

Make saveProjectId async function
Test it (without using timeout)

Signed-off-by: campionfellin <[email protected]>
  • Loading branch information
campionfellin authored and grant committed May 5, 2018
1 parent 73765e0 commit 39e0690
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ export async function checkIfOnline() {
* Saves the script ID in the project dotfile.
* @param {string} scriptId The script ID
*/
export function saveProjectId(scriptId: string): void {
DOTFILE.PROJECT().write({ scriptId }); // Save the script id
export async function saveProjectId(scriptId: string): Promise<string> {
return DOTFILE.PROJECT().write({ scriptId }); // Save the script id
}

/**
Expand Down
34 changes: 31 additions & 3 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { describe, it } from 'mocha';
import { expect } from 'chai';
import * as fs from 'fs';
const { spawnSync } = require('child_process');
import { getScriptURL, getFileType } from './../src/utils.js';
import { getScriptURL, getFileType, getAPIFileType,
saveProjectId } from './../src/utils.js';
const path = require('path');

describe('Test help for each function', () => {
it('should output help for run command', () => {
Expand Down Expand Up @@ -163,21 +165,43 @@ describe.skip('Test clasp version and versions function', () => {
});
});

describe.skip('Test getScriptURL function from utils', () => {
describe('Test getScriptURL function from utils', () => {
it('should return the scriptURL correctly', () => {
const url = getScriptURL('abcdefghijklmnopqrstuvwxyz');
expect(url).to.equal('https://script.google.com/d/abcdefghijklmnopqrstuvwxyz/edit');
});
});

describe.skip('Test getFileType function from utils', () => {
describe('Test getFileType function from utils', () => {
it('should return the lowercase file type correctly', () => {
expect(getFileType('SERVER_JS')).to.equal('js');
expect(getFileType('GS')).to.equal('gs');
expect(getFileType('JS')).to.equal('js');
});
});

describe('Test getAPIFileType function from utils', () => {
it('should return the uppercase file type correctly', () => {
expect(getAPIFileType('file.GS')).to.equal('SERVER_JS');
expect(getAPIFileType('file.JS')).to.equal('SERVER_JS');
expect(getAPIFileType('file.js')).to.equal('SERVER_JS');
expect(getAPIFileType('file.jsx')).to.equal('JSX');
expect(getAPIFileType('file.js.html')).to.equal('HTML');
});
});

describe('Test saveProjectId function from utils', () => {
it('should save the scriptId correctly', () => {
spawnSync('rm', ['.clasp.json']);
const isSaved = async () => {
await saveProjectId('12345');
const id = fs.readFileSync(path.join(__dirname, '/../.clasp.json'), 'utf8');
expect(id).to.equal('{"scriptId":"12345"}');
};
expect(isSaved).to.not.equal(null);
});
});

// Fails when you logged in using --ownkey flag
describe.skip('Test clasp logout function', () => {
it('should logout correctly', () => {
Expand Down Expand Up @@ -216,6 +240,10 @@ describe.skip('Test clasp logout function', () => {
* [ ] clasp redeploy <deploymentId> <version> <description>
* [ ] clasp version [description]
* [x] clasp versions
* [x] saveProjectId
* [x] getScriptURL
* [x] getFileType
* [x] getAPIFileType
*
* # Configs
* - .js and .gs files
Expand Down

0 comments on commit 39e0690

Please sign in to comment.