Skip to content

Commit

Permalink
TDD: add tests for testing, updating file metadata (description, appP…
Browse files Browse the repository at this point in the history
…roperties) for TODO drive.x.updateMetadata
  • Loading branch information
DrPaulBrewer committed Jan 13, 2018
1 parent 270d226 commit adea0d5
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 18 deletions.
41 changes: 41 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ describe('decorated-google-drive:', function(){
})
);
});

it("searching all folders or a file with appProperties: { 'role': 'documentation' } should be empty ", function(){
return (drive.x.searcher({
appProperties: {
'role': 'documentation'
}
})().then((info)=>{
assert.ok(info.files.length===0, "info.files should be empty");
})
);
});

it("checking existence of /path/to/test/Files/README.md with drive.x.findPath should yield expected file metadata", function(){
return drive.x.findPath("/path/to/test/Files/README.md").then((info)=>{
Expand Down Expand Up @@ -216,12 +227,42 @@ describe('decorated-google-drive:', function(){
(e)=>{ if (e.isBoom && e.typeof===Boom.notFound) return Promise.resolve("ok, got Boom 404"); throw e; }
);
});

it("downloading content with drive.x.download should yield contents string including 'License: MIT'", function(){
return drive.x.download("/path/to/test/Files/README.md").then((contents)=>{
contents.should.be.type('string');
assert.ok(contents.includes("License: MIT"));
});
});

it("updating README.md appProperties to {'role': 'documentation'} should succeed", function(){
return (drive.x.findPath("/path/to/test/Files/README.md")
.then((file)=>(drive.x.updateMetadata(file.id, { appProperties: {role: 'documentation'}, description: "read this first" })))
.then((info)=>{
// checks response from drive.x.updateMetadata
info.appProperties.role.should.equal('documentation');
info.description.should.equal('read this first');
return drive.files.get({fileId: info.id, fields: "id,name,description,appProperties"});
}).then((info)=>{
// checks response from subsequent drive.files.get
info.description.should.equal("read this first");
info.appProperties.role.should.equal('documentation');
})
);
});

it("searching all folders or a file with appProperties: { 'role': 'documentation' } should find README.md ", function(){
return (drive.x.searcher({
appProperties: {
'role': 'documentation'
}
})().then((info)=>{
assert.ok(info.files.length===1, "info.files should contain one file");
assert.ok(info.files[0].name==="README.md", "info.files[0].name should be README.md");
})
);
});

it("drive.x.upload2 uploading the file again with {clobber:false} will throw Boom.conflict error because file already exists", function(){
return drive.x.upload2({
folderPath: '/path/to/test/Files/',
Expand Down
64 changes: 46 additions & 18 deletions testResults.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@
✓ drive should not be undefined
✓ drive.x should be an object
drive.x.aboutMe
✓ should return the test users email address (431ms)
✓ should return a storageQuota object with properties limit, usage (163ms)
✓ drive.about.get still works, as well, and the outputs match (165ms)
✓ should return the test users email address (531ms)
✓ should return a storageQuota object with properties limit, usage (194ms)
✓ drive.about.get still works, as well, and the outputs match (166ms)
drive.x.appDataFolder.upload2: upload a string to appDataFolder
✓ uploading the string to appDataFolder file myaccount should resolve with expected file metadata
✓ drive.x.appDataFolder.searcher should report there is exactly one myaccount file in the folder and it should match upload file id
✓ drive.x.appDataFolder.contents should resolve to contents Hello-World-Test-1-2-3
drive.x.upload2: upload a file README.md to Drive folder /path/to/test/Files
✓ uploading the README.md file to /path/to/test/Files/README.md should resolve with expected file metadata
✓ the parents[0] folder should have the name 'Files' (223ms)
✓ searching the parents[0] folder for README.md find a file with matching id (219ms)
✓ the parents[0] folder should have the name 'Files' (152ms)
✓ searching the parents[0] folder for README.md find a file with matching id (199ms)
after drive.x.upload2
✓ searching root for anything should yield folder 'path' with .isFolder===true (198ms)
✓ searching root for folders should yield folder 'path' with .isFolder===true (200ms)
✓ searching root for non-folders should be empty (193ms)
✓ searching all folders for any non-trashed file should be non-empty and include file README.md in results (207ms)
✓ checking existence of /path/to/test/Files/README.md with drive.x.findPath should yield expected file metadata (1051ms)
✓ checking existence of /path/to/test should yield expected folder metadata (684ms)
✓ searching root for anything should yield folder 'path' with .isFolder===true (194ms)
✓ searching root for folders should yield folder 'path' with .isFolder===true (192ms)
✓ searching root for non-folders should be empty (238ms)
✓ searching all folders for any non-trashed file should be non-empty and include file README.md in results (221ms)
✓ searching all folders or a file with appProperties: { 'role': 'documentation' } should be empty (183ms)
✓ checking existence of /path/to/test/Files/README.md with drive.x.findPath should yield expected file metadata (1033ms)
✓ checking existence of /path/to/test should yield expected folder metadata (605ms)
✓ checking existence on wrong path should throw Boom.notfound (188ms)
✓ downloading content with drive.x.download should yield contents string including 'License: MIT' (1260ms)
✓ drive.x.upload2 uploading the file again with {clobber:false} will throw Boom.conflict error because file already exists (968ms)
✓ downloading content with drive.x.download should yield contents string including 'License: MIT' (1251ms)
1) updating README.md appProperties to {'role': 'documentation'} should succeed
2) searching all folders or a file with appProperties: { 'role': 'documentation' } should find README.md
✓ drive.x.upload2 uploading the file again with {clobber:false} will throw Boom.conflict error because file already exists (1001ms)
drive.x.upload2: upload test/test.zip to Drive folder /path/to/test/Files
✓ uploading the test.zip file to /path/to/test/Files/test.zip should resolve with expected file metadata and md5 match
create folder /path/to/test2
Expand All @@ -40,12 +43,37 @@
use folderId of /path/to/test2 to upload test.zip
✓ uploading the test.zip file to /path/to/test2/test.zip should resolve with expected file metadata and md5 match
cleanup via drive.x.janitor
✓ janitor hopefully deletes the README.md file(s) OK and resolves correctly (1364ms)
✓ drive.x.findPath will throw Boom.notFound if the file was successfully deleted (1001ms)
✓ janitor will throw an error if told to delete an invalid file (138ms)
✓ janitor hopefully deletes the README.md file(s) OK and resolves correctly (1376ms)
✓ drive.x.findPath will throw Boom.notFound if the file was successfully deleted (981ms)
✓ janitor will throw an error if told to delete an invalid file (145ms)
✓ janitor should not throw an error if given an empty filelist
✓ final cleanup: delete the path folder and check non-existence (988ms)
✓ final cleanup: delete the path folder and check non-existence (955ms)


36 passing (22s)
2 failing

1) decorated-google-drive:
after drive.x.upload2
updating README.md appProperties to {'role': 'documentation'} should succeed:
TypeError: drive.x.updateMetadata is not a function
at drive.x.findPath.then (test/index.js:240:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)

2) decorated-google-drive:
after drive.x.upload2
searching all folders or a file with appProperties: { 'role': 'documentation' } should find README.md :

AssertionError [ERR_ASSERTION]: info.files should contain one file
+ expected - actual

-false
+true

at drive.x.searcher.then (test/index.js:260:10)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)


35 passing (20s)

0 comments on commit adea0d5

Please sign in to comment.