Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
dblythy committed Jan 14, 2025
commit d1ce9509b2efec15a493d90a283067b499eb951d
2 changes: 2 additions & 0 deletions cloud/TestObject/beforeSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class TestObjectBeforeSave {
this.validateRequest();
this.addBeforeSaveFlag(object);
await this.performAdditionalProcessing(object);

throw new Parse.Error(9001, 'Saving test objects is not available.');
}

validateRequest() {
Expand Down
4 changes: 2 additions & 2 deletions e2e/Tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ describe('Parse Server example', () => {
});

it('call async function', async () => {
const result = await Parse.Cloud.run('asyncFunction');
const result = await Parse.Cloud.run('helloAsyncFunction');
expect(result).toBe('Hi async');
});

it('failing test', async () => {
const obj = new Parse.Object('Test');
const obj = new Parse.Object('TestObject');
await expectAsync(obj.save()).toBeRejectedWith(
new Parse.Error(9001, 'Saving test objects is not available.')
);
Expand Down
11 changes: 9 additions & 2 deletions tests/TestObject/beforeSave.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("TestObject beforeSave", () => {
const addBeforeSaveFlagSpy = jest.spyOn(testObject, "addBeforeSaveFlag");
const performAdditionalProcessingSpy = jest.spyOn(testObject, "performAdditionalProcessing");

await testObject.execute();
await testObject.execute().catch(() => {}); // Catch the expected throw to allow assertions.

expect(validateRequestSpy).toHaveBeenCalledTimes(1);
expect(addBeforeSaveFlagSpy).toHaveBeenCalledWith(mockObject);
Expand All @@ -61,10 +61,17 @@ describe("TestObject beforeSave", () => {

it("should set both beforeSave flag and additional data", async () => {
const testObject = new TestObjectBeforeSave(mockRequest);
await testObject.execute();
await testObject.execute().catch(() => {}); // Catch the expected throw to allow assertions.

expect(mockObject.set).toHaveBeenCalledWith("beforeSave", true);
expect(mockObject.set).toHaveBeenCalledWith("additionalData", "mockedData");
});

it("should throw an error with code 9001", async () => {
const testObject = new TestObjectBeforeSave(mockRequest);
await expect(testObject.execute()).rejects.toThrowError(
new Parse.Error(9001, "Saving test objects is not available.")
);
});
});
});
Loading