|
| 1 | + |
| 2 | +describe("files", function() { |
| 3 | + describe("#Saving base64", function(){ |
| 4 | + this.timeout(10000); |
| 5 | + it("should be saved", function(done){ |
| 6 | + var base64 = "d29ya2luZyBhdCBhdm9zY2xvdWQgaXMgZ3JlYXQh"; |
| 7 | + var file = new AV.File("myfile.txt", { base64: base64 }); |
| 8 | + file.metaData('format', 'txt file'); |
| 9 | + file.setACL(new AV.ACL()); |
| 10 | + file.save().then(function(){ |
| 11 | + // console.log(file.url()); |
| 12 | + // console.log(file.id); |
| 13 | + expect(file.ownerId()).to.be.ok(); |
| 14 | + expect(file.id).to.be.ok(); |
| 15 | + expect(file.metaData('format')).to.be('txt file'); |
| 16 | + file.destroy().then(function(){ |
| 17 | + done(); |
| 18 | + }, function(error){ |
| 19 | + done(error); |
| 20 | + }); |
| 21 | + }, function(error){ |
| 22 | + done(error); |
| 23 | + }); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe("#Test withURL", function(){ |
| 28 | + this.timeout(10000); |
| 29 | + it("should be saved", function(done){ |
| 30 | + var url = "http://i1.wp.com/blog.avoscloud.com/wp-content/uploads/2014/05/screen568x568-1.jpg?resize=202%2C360"; |
| 31 | + var file = AV.File.withURL('screen.jpg', url); |
| 32 | + file.save().then(function(){ |
| 33 | + // console.log(file.url()); |
| 34 | + // console.log(file.id); |
| 35 | + expect(file.ownerId()).to.be.ok(); |
| 36 | + expect(file.id).to.be.ok(); |
| 37 | + expect(file.metaData('__source')).to.be('external'); |
| 38 | + done(); |
| 39 | + }, function(error){ |
| 40 | + done(error); |
| 41 | + }); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe("#Saving buffer in node.js", function(){ |
| 46 | + it("should be saved", function(done){ |
| 47 | + if(AV._isNode){ |
| 48 | + var file = new AV.File('myfile.txt', new Buffer('hello world')); |
| 49 | + file.save().then(function(){ |
| 50 | + // console.log("saved buffer..."); |
| 51 | + // console.log(file.url()); |
| 52 | + // console.log(file.id); |
| 53 | + // console.log(file.metaData()); |
| 54 | + expect(file.size()).to.be(11); |
| 55 | + expect(file.ownerId()).to.be.ok(); |
| 56 | + expect(file.id).to.be.ok(); |
| 57 | + // console.log(file.thumbnailURL(200, 100)); |
| 58 | + expect(file.thumbnailURL(200, 100)).to.be(file.url() + "?imageView/2/w/200/h/100/q/100/format/png"); |
| 59 | + file.destroy().then(function(){ |
| 60 | + done(); |
| 61 | + }, function(error){ |
| 62 | + done(error); |
| 63 | + }); |
| 64 | + }, function(error){ |
| 65 | + done(error); |
| 66 | + }); |
| 67 | + }else{ |
| 68 | + done(); |
| 69 | + } |
| 70 | + }); |
| 71 | + }); |
| 72 | + describe("#Saving array", function(){ |
| 73 | + it("should be saved", function(done){ |
| 74 | + var bytes = [ 0xBE, 0xEF, 0xCA, 0xFE ]; |
| 75 | + var file = new AV.File("myfile.txt", bytes); |
| 76 | + file.save().then(function(){ |
| 77 | + // console.log(file.url()); |
| 78 | + // console.log(file.id); |
| 79 | + // console.log(file.metaData()); |
| 80 | + expect(file.size()).to.be(4); |
| 81 | + expect(file.ownerId()).to.be.ok(); |
| 82 | + expect(file.id).to.be.ok(); |
| 83 | + file.destroy().then(function(){ |
| 84 | + done(); |
| 85 | + }, function(error){ |
| 86 | + done(error); |
| 87 | + }); |
| 88 | + }, function(error){ |
| 89 | + done(error); |
| 90 | + }); |
| 91 | + }); |
| 92 | + }); |
| 93 | + describe("#Saving file with object", function(){ |
| 94 | + it("should be saved", function(done){ |
| 95 | + var bytes = [ 0xBE, 0xEF, 0xCA, 0xFE ]; |
| 96 | + var file = new AV.File("myfile.txt", bytes); |
| 97 | + file.save().then(function(){ |
| 98 | + // console.log(file.url()); |
| 99 | + // console.log(file.id); |
| 100 | + var jobApplication = new AV.Object("JobApplication"); |
| 101 | + jobApplication.set("applicantName", "Joe Smith"); |
| 102 | + jobApplication.set("applicantResumeFile", file); |
| 103 | + jobApplication.save().then(function(result){ |
| 104 | + expect(result.id).to.be.ok(); |
| 105 | + var query = new AV.Query("JobApplication"); |
| 106 | + query.get(result.id, { |
| 107 | + success: function(ja) { |
| 108 | + expect(ja.id).to.be.ok(); |
| 109 | + var arf = ja.get("applicantResumeFile"); |
| 110 | + // console.log(arf.metaData()); |
| 111 | + expect(arf).to.be.ok(); |
| 112 | + expect(arf.size()).to.be(4); |
| 113 | + expect(arf.ownerId()).to.be.ok(); |
| 114 | + // console.log(ja.get("applicantResumeFile")); |
| 115 | + file.destroy().then(function(){ |
| 116 | + done(); |
| 117 | + }, function(error){ |
| 118 | + done(error); |
| 119 | + }); |
| 120 | + }, |
| 121 | + error: function(object, error) { |
| 122 | + done(error); |
| 123 | + } |
| 124 | + }); |
| 125 | + |
| 126 | + }, function(obj, error){ |
| 127 | + done(error); |
| 128 | + }); |
| 129 | + }, function(error){ |
| 130 | + done(error); |
| 131 | + }); |
| 132 | + }); |
| 133 | + }); |
| 134 | +}); |
0 commit comments