GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — parse-server/spec/PurchaseValidation.spec.js at master · cs8/parse-server Expand file tree/ Copy pathPurchaseValidation.spec.jsMore file actions 209 lines (190 loc) · 5.6 KB / Copy pathPurchaseValidation.spec.jsFile metadata and controls209 lines (190 loc) · 5.6 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 var request = require("request"); function createProduct() { const file = new Parse.File("name", { base64: new Buffer("download_file", "utf-8").toString("base64") }, "text"); return file.save().then(function(){ var product = new Parse.Object("_Product"); product.set({ download: file, icon: file, title: "a product", subtitle: "a product", order: 1, productIdentifier: "a-product" }) return product.save(); }) } describe("test validate_receipt endpoint", () => { beforeEach( done => { createProduct().then(done).fail(function(err){ console.error(err); done(); }) }) it("should bypass appstore validation", (done) => { request.post({ headers: { 'X-Parse-Application-Id': 'test', 'X-Parse-REST-API-Key': 'rest'}, url: 'http://localhost:8378/1/validate_purchase', json: true, body: { productIdentifier: "a-product", receipt: { __type: "Bytes", base64: new Buffer("receipt", "utf-8").toString("base64") }, bypassAppStoreValidation: true } }, function(err, res, body){ if (typeof body != "object") { fail("Body is not an object"); done(); } else { expect(body.__type).toEqual("File"); const url = body.url; request.get({ url: url }, function(err, res, body) { expect(body).toEqual("download_file"); done(); }); } }); }); it("should fail for missing receipt", (done) => { request.post({ headers: { 'X-Parse-Application-Id': 'test', 'X-Parse-REST-API-Key': 'rest'}, url: 'http://localhost:8378/1/validate_purchase', json: true, body: { productIdentifier: "a-product", bypassAppStoreValidation: true } }, function(err, res, body){ if (typeof body != "object") { fail("Body is not an object"); done(); } else { expect(body.code).toEqual(Parse.Error.INVALID_JSON); done(); } }); }); it("should fail for missing product identifier", (done) => { request.post({ headers: { 'X-Parse-Application-Id': 'test', 'X-Parse-REST-API-Key': 'rest'}, url: 'http://localhost:8378/1/validate_purchase', json: true, body: { receipt: { __type: "Bytes", base64: new Buffer("receipt", "utf-8").toString("base64") }, bypassAppStoreValidation: true } }, function(err, res, body){ if (typeof body != "object") { fail("Body is not an object"); done(); } else { expect(body.code).toEqual(Parse.Error.INVALID_JSON); done(); } }); }); it("should bypass appstore validation and not find product", (done) => { request.post({ headers: { 'X-Parse-Application-Id': 'test', 'X-Parse-REST-API-Key': 'rest'}, url: 'http://localhost:8378/1/validate_purchase', json: true, body: { productIdentifier: "another-product", receipt: { __type: "Bytes", base64: new Buffer("receipt", "utf-8").toString("base64") }, bypassAppStoreValidation: true } }, function(err, res, body){ if (typeof body != "object") { fail("Body is not an object"); done(); } else { expect(body.code).toEqual(Parse.Error.OBJECT_NOT_FOUND); expect(body.error).toEqual('Object not found.'); done(); } }); }); it("should fail at appstore validation", (done) => { request.post({ headers: { 'X-Parse-Application-Id': 'test', 'X-Parse-REST-API-Key': 'rest'}, url: 'http://localhost:8378/1/validate_purchase', json: true, body: { productIdentifier: "a-product", receipt: { __type: "Bytes", base64: new Buffer("receipt", "utf-8").toString("base64") }, } }, function(err, res, body){ if (typeof body != "object") { fail("Body is not an object"); } else { expect(body.status).toBe(21002); expect(body.error).toBe('The data in the receipt-data property was malformed or missing.'); } done(); }); }); it("should not create a _Product", (done) => { var product = new Parse.Object("_Product"); product.save().then(function(){ fail("Should not be able to save"); done(); }, function(err){ expect(err.code).toEqual(Parse.Error.INCORRECT_TYPE); done(); }) }); it("should be able to update a _Product", (done) => { var query = new Parse.Query("_Product"); query.first().then(function(product){ product.set("title", "a new title"); return product.save(); }).then(function(productAgain){ expect(productAgain.get('downloadName')).toEqual(productAgain.get('download').name()); expect(productAgain.get("title")).toEqual("a new title"); done(); }).fail(function(err){ fail(JSON.stringify(err)); done(); }); }); it("should not be able to remove a require key in a _Product", (done) => { var query = new Parse.Query("_Product"); query.first().then(function(product){ product.unset("title"); return product.save(); }).then(function(productAgain){ fail("Should not succeed"); done(); }).fail(function(err){ expect(err.code).toEqual(Parse.Error.INCORRECT_TYPE); expect(err.message).toEqual("title is required."); done(); }); }); }); |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |