-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new tests and mock structure to drive objects
- Loading branch information
1 parent
8625131
commit 13b95f8
Showing
6 changed files
with
201 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "QuickDrive", | ||
"version": "1.0.0", | ||
"description": "Templates with google spreadsheet", | ||
"author": "Matheus Martins do Rego", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:matheusmr13/quickdrive.git" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^2.5.3" | ||
}, | ||
"devDependencies": {} | ||
} |
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,143 @@ | ||
var DriveApp = function () { | ||
var DriveFolder = function (newId) { | ||
var files = [], | ||
id = newId || ''; | ||
this.getId = function () { | ||
return id; | ||
}; | ||
this.addFile = function (file) { | ||
files.push(file); | ||
}; | ||
this.getFiles = function () { | ||
return files; | ||
}; | ||
}; | ||
|
||
var DriveFile = function (newId) { | ||
var properties = { | ||
id: newId || '', | ||
name: '' | ||
}; | ||
|
||
this.setSharing = function () {}; | ||
this.getId = function () { | ||
return properties.id; | ||
}; | ||
this.makeCopy = function (name, folder) { | ||
var newFile = new DriveFile(); | ||
newFile._setProperties(properties); | ||
newFile.setName(name); | ||
folder.addFile(newFile); | ||
return newFile; | ||
}; | ||
this.getName = function () { | ||
return properties.name; | ||
}; | ||
this.setName = function (newName) { | ||
properties.name = newName; | ||
}; | ||
this._setProperties = function(newProperties) { | ||
for (var propertie in newProperties) { | ||
properties[propertie] = newProperties[propertie]; | ||
} | ||
}; | ||
}; | ||
|
||
return { | ||
Access: { | ||
ANYONE: 'ANYONE', | ||
ANYONE_WITH_LINK: 'ANYONE_WITH_LINK', | ||
DOMAIN: 'DOMAIN', | ||
DOMAIN_WITH_LINK: 'DOMAIN_WITH_LINK', | ||
PRIVATE: 'PRIVATE' | ||
}, | ||
Permission: { | ||
COMMENT: 'COMMENT', | ||
EDIT: 'EDIT', | ||
NONE: 'NONE', | ||
OWNER: 'OWNER', | ||
VIEW: 'VIEW' | ||
}, | ||
getFileById: function (id) { | ||
return new DriveFile(id); | ||
}, | ||
getFolderById: function (id) { | ||
return new DriveFolder(id); | ||
} | ||
}; | ||
}; | ||
|
||
var SpreadsheetApp = function () { | ||
var SpreadSheetMock = function (mySheets) { | ||
var sheets = mySheets || []; | ||
|
||
this.getSheets = function () { | ||
return sheets; | ||
}; | ||
var SheetMock = function (myMatrix) { | ||
var matrix = myMatrix || [ | ||
[] | ||
]; | ||
|
||
var CellMock = function () { | ||
var value = ""; | ||
this.setValue = function (newValue) { | ||
this.value = newValue; | ||
}; | ||
|
||
this.getValue = function () { | ||
return value; | ||
}; | ||
}; | ||
|
||
var CellGroupMock = function (matrix) { | ||
var matrix = matrix || [ | ||
[] | ||
]; | ||
|
||
this.getValues = function () { | ||
var values = []; | ||
for (var i = row; i < lines; i++) { | ||
values[i] = []; | ||
for (var j = col; j < cols; j++) { | ||
values[i][j] = matrix[i][j]; | ||
} | ||
} | ||
return values; | ||
}; | ||
|
||
this.setValue = function (value) { | ||
for (var i = 0; i < matrix.length; i++) { | ||
for (var j = 0; j < matrix.length; j++) { | ||
matrix[i][j] = value; | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
SheetMock.getRange = function (row, col, lines, cols) { | ||
var newMatrix = [ | ||
[] | ||
]; | ||
for (var i = row; i < lines; i++) { | ||
newMatrix[i] = []; | ||
for (var j = col; j < cols; j++) { | ||
newMatrix[i][j]; | ||
} | ||
} | ||
return new CellGroupMock(newMatrix); | ||
}; | ||
}; | ||
}; | ||
|
||
return { | ||
open: function (file) { | ||
return new SpreadSheetMock(); | ||
} | ||
} | ||
}; | ||
|
||
exports.DriveAppMock = { | ||
DriveApp: DriveApp, | ||
SpreadsheetApp: SpreadsheetApp | ||
}; |
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 @@ | ||
var DocApp = {} |
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,24 @@ | ||
var mock = require('./mock/DriveAppMock.js').DriveAppMock; | ||
var SpreadsheetApp = mock.SpreadsheetApp(); | ||
var DriveApp = mock.DriveApp(); | ||
var assert = require('chai').assert; | ||
|
||
describe('DriveApp sheet mock test', function () { | ||
describe('copy of file with name in folder', function () { | ||
it('it should return file with specified id', function () { | ||
var file = DriveApp.getFileById('myFileId'); | ||
assert.equal('myFileId', file.getId()); | ||
}); | ||
it('it should return folder with specified id', function () { | ||
var folder = DriveApp.getFolderById('myFolderId'); | ||
assert.equal('myFolderId', folder.getId()); | ||
}); | ||
it('it should return file and folder should have one file', function () { | ||
var folder = DriveApp.getFolderById('myFolderId'); | ||
var file = DriveApp.getFileById('myFileId'); | ||
var newFile = file.makeCopy('my new file name', folder); | ||
assert.equal('my new file name', newFile.getName()); | ||
assert.equal(1, folder.getFiles().length); | ||
}); | ||
}); | ||
}); |
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