Files
kami-parse-server/spec/PurchaseValidation.spec.js

209 lines
5.7 KiB
JavaScript
Raw Normal View History

const request = require("request");
2016-02-19 13:06:02 -05:00
function createProduct() {
const file = new Parse.File("name", {
base64: new Buffer("download_file", "utf-8").toString("base64")
}, "text");
return file.save().then(function(){
const product = new Parse.Object("_Product");
2016-02-19 13:06:02 -05:00
product.set({
download: file,
2016-02-19 13:06:02 -05:00
icon: file,
title: "a product",
subtitle: "a product",
order: 1,
productIdentifier: "a-product"
})
return product.save();
})
}
2016-02-19 13:06:02 -05:00
describe("test validate_receipt endpoint", () => {
beforeEach(done => {
createProduct().then(done).fail(function(){
2016-02-19 13:06:02 -05:00
done();
Advancements with postgres (#2510) * Start DB runner from tests * Connect GridstoreAdapter only when needed * removes unused package * better test errors reporting * Adds support for __op.Delete * Better test error reporting * Makes sure all tests can run without crashing * Use xdescribe to skip test suite * Removes unused dependencies * Let volatiles classes be created with PG on start * Do not fail if class dont exist * adds index.spec.js to the pg suite * Use a new config each test to prevent side effects * Enable EmailVerificationToken specs with pg * Makes sure failure output is not cut * Reduces number of ignored tests in ParseObject.spec * Inspect reconfiguration errors * Mark GlobalConfig is incompatible with PG - Problem is with nested updates (param.prop = value) * PG: Nested JSON queries and updates - Adds support for nested json and . operator queries - Adds debug support for PG adapter - Adds loglevel support in helper * Enable working specs in ParseUser * Sets default logLevel in tests to undefined * Adds File type support, retores purchaseValidation specs * Adds support for updating jsonb objects - Restores PushController tests * Proper implementation of deleteByQuery and ORs - Adds ParseInstallation spec to the test suite * xit only failing tests * Nit on ParseAPI spec * add sorting operator * properly bound order keys * reverts describe_only_db behavior * Enables passing tests * Adds basic support for relations, upsertOneObject aliased to createObject * progress on queries options * Fix ACL update related problems * Creates relation tables on class creation * Adds Relation tests * remove flaky tests * use promises instead of CB * disable flaky test * nits * Fixes on schema spec - Next thing is to implemenet geopoint and files correctly * fix failues * Basic GeoPoint support * Adds support for $nearSphere/$maxDistance geopoint queries * enable passing tests * drop tables afterEach for PG, clean up relation tables too * Better initialization/dropTables
2016-08-15 16:48:39 -04:00
});
2016-02-19 13:06:02 -05:00
})
it("should bypass appstore validation", (done) => {
request.post({
2016-02-19 13:06:02 -05:00
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",
2016-02-19 13:06:02 -05:00
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();
2016-02-19 13:06:02 -05:00
} else {
expect(body.__type).toEqual("File");
const url = body.url;
request.get({
url: url
}, function(err, res, body) {
expect(body).toEqual("download_file");
done();
});
}
});
});
2016-02-19 13:06:02 -05:00
it("should fail for missing receipt", (done) => {
request.post({
2016-02-19 13:06:02 -05:00
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",
2016-02-19 13:06:02 -05:00
bypassAppStoreValidation: true
}
}, function(err, res, body){
if (typeof body != "object") {
fail("Body is not an object");
done();
2016-02-19 13:06:02 -05:00
} else {
expect(body.code).toEqual(Parse.Error.INVALID_JSON);
done();
}
});
});
2016-02-19 13:06:02 -05:00
it("should fail for missing product identifier", (done) => {
request.post({
2016-02-19 13:06:02 -05:00
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();
2016-02-19 13:06:02 -05:00
} else {
expect(body.code).toEqual(Parse.Error.INVALID_JSON);
done();
}
});
});
2016-02-19 13:06:02 -05:00
it("should bypass appstore validation and not find product", (done) => {
request.post({
2016-02-19 13:06:02 -05:00
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",
2016-02-19 13:06:02 -05:00
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({
2016-02-19 13:06:02 -05:00
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",
2016-02-19 13:06:02 -05:00
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();
});
});
Advancements with postgres (#2510) * Start DB runner from tests * Connect GridstoreAdapter only when needed * removes unused package * better test errors reporting * Adds support for __op.Delete * Better test error reporting * Makes sure all tests can run without crashing * Use xdescribe to skip test suite * Removes unused dependencies * Let volatiles classes be created with PG on start * Do not fail if class dont exist * adds index.spec.js to the pg suite * Use a new config each test to prevent side effects * Enable EmailVerificationToken specs with pg * Makes sure failure output is not cut * Reduces number of ignored tests in ParseObject.spec * Inspect reconfiguration errors * Mark GlobalConfig is incompatible with PG - Problem is with nested updates (param.prop = value) * PG: Nested JSON queries and updates - Adds support for nested json and . operator queries - Adds debug support for PG adapter - Adds loglevel support in helper * Enable working specs in ParseUser * Sets default logLevel in tests to undefined * Adds File type support, retores purchaseValidation specs * Adds support for updating jsonb objects - Restores PushController tests * Proper implementation of deleteByQuery and ORs - Adds ParseInstallation spec to the test suite * xit only failing tests * Nit on ParseAPI spec * add sorting operator * properly bound order keys * reverts describe_only_db behavior * Enables passing tests * Adds basic support for relations, upsertOneObject aliased to createObject * progress on queries options * Fix ACL update related problems * Creates relation tables on class creation * Adds Relation tests * remove flaky tests * use promises instead of CB * disable flaky test * nits * Fixes on schema spec - Next thing is to implemenet geopoint and files correctly * fix failues * Basic GeoPoint support * Adds support for $nearSphere/$maxDistance geopoint queries * enable passing tests * drop tables afterEach for PG, clean up relation tables too * Better initialization/dropTables
2016-08-15 16:48:39 -04:00
it("should not create a _Product", (done) => {
const 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();
})
2016-02-19 13:06:02 -05:00
});
it("should be able to update a _Product", (done) => {
const query = new Parse.Query("_Product");
query.first().then(function(product) {
if (!product) {
return Promise.reject(new Error('Product should be found'));
}
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();
});
2016-02-19 13:06:02 -05:00
});
it("should not be able to remove a require key in a _Product", (done) => {
const query = new Parse.Query("_Product");
query.first().then(function(product){
if (!product) {
return Promise.reject(new Error('Product should be found'));
}
product.unset("title");
return product.save();
}).then(function(){
fail("Should not succeed");
done();
}).fail(function(err){
expect(err.code).toEqual(Parse.Error.INCORRECT_TYPE);
expect(err.message).toEqual("title is required.");
done();
});
2016-02-19 13:06:02 -05:00
});
});