ci: Fix CI not testing with Postgres 16 and flaky test (#9210)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
const batch = require('../lib/batch');
|
||||
const request = require('../lib/request');
|
||||
const TestUtils = require('../lib/TestUtils');
|
||||
|
||||
const originalURL = '/parse/batch';
|
||||
const serverURL = 'http://localhost:1234/parse';
|
||||
@@ -18,9 +17,13 @@ const headers = {
|
||||
};
|
||||
|
||||
describe('batch', () => {
|
||||
let createSpy;
|
||||
beforeEach(async () => {
|
||||
createSpy = spyOn(databaseAdapter, 'createObject').and.callThrough();
|
||||
});
|
||||
|
||||
it('should return the proper url', () => {
|
||||
const internalURL = batch.makeBatchRoutingPathFunction(originalURL)('/parse/classes/Object');
|
||||
|
||||
expect(internalURL).toEqual('/classes/Object');
|
||||
});
|
||||
|
||||
@@ -133,8 +136,6 @@ describe('batch', () => {
|
||||
});
|
||||
|
||||
it('should handle a batch request without transaction', async () => {
|
||||
spyOn(databaseAdapter, 'createObject').and.callThrough();
|
||||
|
||||
const response = await request({
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
@@ -154,7 +155,6 @@ describe('batch', () => {
|
||||
],
|
||||
}),
|
||||
});
|
||||
|
||||
expect(response.data.length).toEqual(2);
|
||||
expect(response.data[0].success.objectId).toBeDefined();
|
||||
expect(response.data[0].success.createdAt).toBeDefined();
|
||||
@@ -162,15 +162,13 @@ describe('batch', () => {
|
||||
expect(response.data[1].success.createdAt).toBeDefined();
|
||||
const query = new Parse.Query('MyObject');
|
||||
const results = await query.find();
|
||||
expect(databaseAdapter.createObject.calls.count()).toBe(2);
|
||||
expect(databaseAdapter.createObject.calls.argsFor(0)[3]).toEqual(null);
|
||||
expect(databaseAdapter.createObject.calls.argsFor(1)[3]).toEqual(null);
|
||||
expect(createSpy.calls.count()).toBe(2);
|
||||
expect(createSpy.calls.argsFor(0)[3]).toEqual(null);
|
||||
expect(createSpy.calls.argsFor(1)[3]).toEqual(null);
|
||||
expect(results.map(result => result.get('key')).sort()).toEqual(['value1', 'value2']);
|
||||
});
|
||||
|
||||
it('should handle a batch request with transaction = false', async () => {
|
||||
spyOn(databaseAdapter, 'createObject').and.callThrough();
|
||||
|
||||
const response = await request({
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
@@ -196,11 +194,12 @@ describe('batch', () => {
|
||||
expect(response.data[0].success.createdAt).toBeDefined();
|
||||
expect(response.data[1].success.objectId).toBeDefined();
|
||||
expect(response.data[1].success.createdAt).toBeDefined();
|
||||
|
||||
const query = new Parse.Query('MyObject');
|
||||
const results = await query.find();
|
||||
expect(databaseAdapter.createObject.calls.count()).toBe(2);
|
||||
expect(databaseAdapter.createObject.calls.argsFor(0)[3]).toEqual(null);
|
||||
expect(databaseAdapter.createObject.calls.argsFor(1)[3]).toEqual(null);
|
||||
expect(createSpy.calls.count()).toBe(2);
|
||||
expect(createSpy.calls.argsFor(0)[3]).toEqual(null);
|
||||
expect(createSpy.calls.argsFor(1)[3]).toEqual(null);
|
||||
expect(results.map(result => result.get('key')).sort()).toEqual(['value1', 'value2']);
|
||||
});
|
||||
|
||||
@@ -209,24 +208,11 @@ describe('batch', () => {
|
||||
process.env.PARSE_SERVER_TEST_DB === 'postgres'
|
||||
) {
|
||||
describe('transactions', () => {
|
||||
beforeEach(async () => {
|
||||
await TestUtils.destroyAllDataPermanently(true);
|
||||
if (process.env.MONGODB_TOPOLOGY === 'replicaset') {
|
||||
await reconfigureServer({
|
||||
databaseAdapter: undefined,
|
||||
databaseURI:
|
||||
'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase?replicaSet=replicaset',
|
||||
});
|
||||
} else {
|
||||
await reconfigureServer();
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle a batch request with transaction = true', async () => {
|
||||
const myObject = new Parse.Object('MyObject'); // This is important because transaction only works on pre-existing collections
|
||||
await myObject.save();
|
||||
await myObject.destroy();
|
||||
spyOn(databaseAdapter, 'createObject').and.callThrough();
|
||||
createSpy.calls.reset();
|
||||
const response = await request({
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
@@ -254,10 +240,10 @@ describe('batch', () => {
|
||||
expect(response.data[1].success.createdAt).toBeDefined();
|
||||
const query = new Parse.Query('MyObject');
|
||||
const results = await query.find();
|
||||
expect(databaseAdapter.createObject.calls.count() % 2).toBe(0);
|
||||
for (let i = 0; i + 1 < databaseAdapter.createObject.calls.length; i = i + 2) {
|
||||
expect(databaseAdapter.createObject.calls.argsFor(i)[3]).toBe(
|
||||
databaseAdapter.createObject.calls.argsFor(i + 1)[3]
|
||||
expect(createSpy.calls.count()).toBe(2);
|
||||
for (let i = 0; i + 1 < createSpy.calls.length; i = i + 2) {
|
||||
expect(createSpy.calls.argsFor(i)[3]).toBe(
|
||||
createSpy.calls.argsFor(i + 1)[3]
|
||||
);
|
||||
}
|
||||
expect(results.map(result => result.get('key')).sort()).toEqual(['value1', 'value2']);
|
||||
@@ -265,9 +251,11 @@ describe('batch', () => {
|
||||
|
||||
it('should not save anything when one operation fails in a transaction', async () => {
|
||||
const myObject = new Parse.Object('MyObject'); // This is important because transaction only works on pre-existing collections
|
||||
await myObject.save();
|
||||
await myObject.save({ key: 'stringField' });
|
||||
await myObject.destroy();
|
||||
createSpy.calls.reset();
|
||||
try {
|
||||
// Saving a number to a string field should fail
|
||||
await request({
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
@@ -386,8 +374,7 @@ describe('batch', () => {
|
||||
const myObject2 = new Parse.Object('MyObject2'); // This is important because transaction only works on pre-existing collections
|
||||
await myObject2.save();
|
||||
await myObject2.destroy();
|
||||
|
||||
spyOn(databaseAdapter, 'createObject').and.callThrough();
|
||||
createSpy.calls.reset();
|
||||
|
||||
let myObjectCalls = 0;
|
||||
Parse.Cloud.beforeSave('MyObject', async () => {
|
||||
|
||||
Reference in New Issue
Block a user