Skip to content

Commit

Permalink
add "parents" to default field list for search/create/upload requests…
Browse files Browse the repository at this point in the history
…; add some tests; tests pass
  • Loading branch information
DrPaulBrewer committed Jan 12, 2018
1 parent 0873e77 commit b5ae35c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 41 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function extensions(drive, request, rootFolderId, spaces){
const unique = options.unique;
if (unique) limit = 2;
const allowMatchAllFiles = options.allowMatchAllFiles;
const fields = options.fields || 'id,name,mimeType,modifiedTime,size';
const fields = options.fields || 'id,name,mimeType,modifiedTime,size,parents';
const searchTerms = ssgd.extract(options);

return function(parent, name){
Expand Down Expand Up @@ -188,7 +188,7 @@ function extensions(drive, request, rootFolderId, spaces){
};
return pify(drive.files.create)({
resource: metadata,
fields: 'id, mimeType, name'
fields: 'id, mimeType, name, parents'
}).then(addNew).then(addIsFolder);
})
);
Expand Down Expand Up @@ -276,7 +276,7 @@ function extensions(drive, request, rootFolderId, spaces){
const meta = Object.assign({}, metadata, {parents: [parent], spaces});
const req = drive.files.create({
resource: meta,
fields: 'id,name,mimeType,md5Checksum'
fields: 'id,name,mimeType,md5Checksum,parents'
},{
url: "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable"
});
Expand Down
25 changes: 23 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('decorated-google-drive:', function(){
});
it("uploading the string to appDataFolder file myaccount should resolve with expected file metadata", function(){
uploadResult.should.be.type("object");
uploadResult.should.have.properties('id','name','mimeType','isNew');
uploadResult.should.have.properties('id','name','mimeType','isNew','parents');
uploadResult.name.should.equal("myaccount");
uploadResult.mimeType.should.equal("text/plain");
uploadResult.isNew.should.equal(true);
Expand Down Expand Up @@ -124,6 +124,22 @@ describe('decorated-google-drive:', function(){
assert.ok(uploadResult.parents.length===1, "uploadResult.parents.length should be 1");
uploadResult.parents[0].should.be.type('string');
});
it("the parents[0] folder should have the name 'Files'", function(done){
drive.files.get({fileId: uploadResult.parents[0]}, function(e,data){
if (e) throw e;
data.name.should.equal('Files');
done();
});
});
it("searching the parents[0] folder for README.md find a file with matching id", function(){
return (drive.x.searcher({trashed:false})(uploadResult.parents[0], 'README.md')
.then((info)=>{
assert.ok(Array.isArray(info.files), "info.files is array");
info.files[0].name.should.equal('README.md');
info.files[0].id.should.equal(uploadResult.id);
})
);
});
});
describe(' after drive.x.upload2 ', function(){
it("searching root for anything should yield folder 'path' with .isFolder===true", function(){
Expand Down Expand Up @@ -249,7 +265,7 @@ describe('decorated-google-drive:', function(){
});
it(' the resolved folder object should be an object with props id, name, mimeType, isFolder ' , function(){
test2Folder.should.be.type("object");
test2Folder.should.have.properties('id','name','mimeType','isFolder','isNew');
test2Folder.should.have.properties('id','name','mimeType','isFolder','isNew','parents');
});
it(' the folder.id should be a string with length >4 ',function(){
test2Folder.id.should.be.type('string');
Expand All @@ -267,6 +283,11 @@ describe('decorated-google-drive:', function(){
it( ' isFolder should be true ', function(){
test2Folder.isFolder.should.equal(true);
});
it( ' parents should be an Array containing 1 string ', function(){
assert.ok(Array.isArray(test2Folder.parents), "test2Folder.parents should be an Array");
assert.ok(test2Folder.parents.length===1, "test2Folder.parents.length should be 1");
test2Folder.parents[0].should.be.type('string');
});
});
describe(' use folderId of /path/to/test2 to upload test.zip ', function(){
let uploadResult = null;
Expand Down
57 changes: 21 additions & 36 deletions testResults.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@
✓ drive should not be undefined
✓ drive.x should be an object
drive.x.aboutMe
✓ should return the test users email address (498ms)
✓ should return a storageQuota object with properties limit, usage (176ms)
✓ drive.about.get still works, as well, and the outputs match (199ms)
✓ should return the test users email address (286ms)
✓ should return a storageQuota object with properties limit, usage (166ms)
✓ drive.about.get still works, as well, and the outputs match (112ms)
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
1) uploading the README.md file to /path/to/test/Files/README.md should resolve with expected file metadata
✓ 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' (100ms)
✓ searching the parents[0] folder for README.md find a file with matching id (146ms)
after drive.x.upload2
✓ searching root for anything should yield folder 'path' with .isFolder===true (189ms)
✓ searching root for folders should yield folder 'path' with .isFolder===true (256ms)
✓ searching root for non-folders should be empty (215ms)
✓ searching all folders for any non-trashed file should be non-empty and include file README.md in results (295ms)
✓ checking existence of /path/to/test/Files/README.md with drive.x.findPath should yield expected file metadata (1032ms)
✓ checking existence of /path/to/test should yield expected folder metadata (636ms)
✓ checking existence on wrong path should throw Boom.notfound (211ms)
✓ downloading content with drive.x.download should yield contents string including 'License: MIT' (1423ms)
✓ drive.x.upload2 uploading the file again with {clobber:false} will throw Boom.conflict error because file already exists (1027ms)
✓ searching root for anything should yield folder 'path' with .isFolder===true (136ms)
✓ searching root for folders should yield folder 'path' with .isFolder===true (134ms)
✓ searching root for non-folders should be empty (132ms)
✓ searching all folders for any non-trashed file should be non-empty and include file README.md in results (132ms)
✓ checking existence of /path/to/test/Files/README.md with drive.x.findPath should yield expected file metadata (755ms)
✓ checking existence of /path/to/test should yield expected folder metadata (415ms)
✓ checking existence on wrong path should throw Boom.notfound (137ms)
✓ downloading content with drive.x.download should yield contents string including 'License: MIT' (927ms)
✓ drive.x.upload2 uploading the file again with {clobber:false} will throw Boom.conflict error because file already exists (682ms)
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 @@ -34,33 +36,16 @@
✓ the mimeType should be application/vnd.google-apps.folder
✓ isNew should be true
✓ isFolder should be true
✓ parents should be an Array containing 1 string
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 (1485ms)
✓ drive.x.findPath will throw Boom.notFound if the file was successfully deleted (1086ms)
✓ janitor will throw an error if told to delete an invalid file (139ms)
✓ janitor hopefully deletes the README.md file(s) OK and resolves correctly (1187ms)
✓ drive.x.findPath will throw Boom.notFound if the file was successfully deleted (697ms)
✓ janitor will throw an error if told to delete an invalid file (79ms)
✓ janitor should not throw an error if given an empty filelist
✓ final cleanup: delete the path folder and check non-existence (1013ms)


31 passing (20s)
1 failing

1) decorated-google-drive:
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:
AssertionError: expected Object {
id: '19HOXNqijkD8LNUtpTmv-LOu4ZQQ8z50N',
name: 'README.md',
mimeType: 'text/plain',
md5Checksum: '6e8f30a63bc2af1a1b9a63e76c3a90ec',
isNew: true,
isFolder: false
} to have property parents
at Assertion.fail (node_modules/should/cjs/should.js:275:17)
at Assertion.value [as properties] (node_modules/should/cjs/should.js:356:19)
at Context.<anonymous> (test/index.js:118:31)
✓ final cleanup: delete the path folder and check non-existence (785ms)


35 passing (15s)

0 comments on commit b5ae35c

Please sign in to comment.