Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
74 changes: 74 additions & 0 deletions spec/ParseGraphQLController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,32 @@ describe('ParseGraphQLController', () => {
],
})
).toBeResolvedTo(successfulUpdateResponse);
expectAsync(
parseGraphQLController.updateGraphQLConfig({
classConfigs: [
{
className: '_User',
mutation: {
createMany: 1,
},
},
],
})
).toBeRejected();
expectAsync(
parseGraphQLController.updateGraphQLConfig({
classConfigs: [
{
className: '_User',
mutation: {
createMany: true,
updateMany: true,
deleteMany: false,
},
},
],
})
).toBeResolvedTo(successfulUpdateResponse);
});

it('should throw if _User create fields is missing username or password', async () => {
Expand Down Expand Up @@ -1043,6 +1069,54 @@ describe('ParseGraphQLController', () => {
).toBeRejected(
`Invalid graphQLConfig: classConfig:${className} is invalid because "mutation.destroyAlias" must be a string`
);

expectAsync(
parseGraphQLController.updateGraphQLConfig({
classConfigs: [
{
className,
mutation: {
createMany: true,
createManyAlias: true,
},
},
],
})
).toBeRejected(
`Invalid graphQLConfig: classConfig:${className} is invalid because "mutation.createManyAlias" must be a string`
);

expectAsync(
parseGraphQLController.updateGraphQLConfig({
classConfigs: [
{
className,
mutation: {
updateMany: true,
updateManyAlias: 1,
},
},
],
})
).toBeRejected(
`Invalid graphQLConfig: classConfig:${className} is invalid because "mutation.updateManyAlias" must be a string`
);

expectAsync(
parseGraphQLController.updateGraphQLConfig({
classConfigs: [
{
className,
mutation: {
deleteMany: true,
deleteManyAlias: { not: 'valid' },
},
},
],
})
).toBeRejected(
`Invalid graphQLConfig: classConfig:${className} is invalid because "mutation.deleteManyAlias" must be a string`
);
Comment on lines +1073 to +1119

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Jasmine expectAsync toBeRejected toBeRejectedWithError signature arguments

💡 Result:

In the Jasmine testing framework, expectAsync is used to create an asynchronous expectation, which returns a promise that must be awaited or returned by the spec [1]. The toBeRejected matcher expects a promise to be rejected, and it takes no arguments [2][3]. The toBeRejectedWithError matcher expects a promise to be rejected with a value that matches the provided parameters [4][5]. It accepts two optional arguments: 1. expected: An Error constructor that the thrown object should be an instance of [4][5]. If this argument is omitted, the default Error constructor is used [4][5]. 2. message: A string or regular expression that the message property of the thrown error must match [4][5]. Example usage: await expectAsync(aPromise).toBeRejectedWithError(MyCustomError, 'Error message'); await expectAsync(aPromise).toBeRejectedWithError(MyCustomError, /Error message/); await expectAsync(aPromise).toBeRejectedWithError(MyCustomError); await expectAsync(aPromise).toBeRejectedWithError('Error message');

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Repository files matching spec/controller:"
git ls-files | rg '(^|/)(ParseGraphQLController\.spec\.js|ParseGraphQLController\.(js|ts))$' || true

file="spec/ParseGraphQLController.spec.js"
if [ -f "$file" ]; then
  echo
  echo "Relevant lines in $file:"
  sed -n '1050,1130p' "$file" | nl -ba -v1050
  echo
  echo "Search for toBeRejected/toBeRejectedWithError usages in spec:"
  rg -n "toBeRejected|toBeRejectedWithError|updateGraphQLConfig" "$file" || true
fi

echo
echo "Package/Jasmine context clues:"
git ls-files | rg '(^package\.json$|^package-lock\.json$|^yarn\.lock$|^pnpm-lock\.yaml$)' || true
if [ -f package.json ]; then
  node -e 'const p=require("./package.json"); console.log(JSON.stringify({dependencies:p.dependencies, devDependencies:p.devDependencies}, null, 2))'
fi

Repository: parse-community/parse-server

Length of output: 384


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="spec/ParseGraphQLController.spec.js"

echo "Relevant lines in $file:"
sed -n '1050,1130p' "$file"

echo
echo "Search for toBeRejected/toBeRejectedWithError usages in spec:"
rg -n "toBeRejected|toBeRejectedWithError|updateGraphQLConfig" "$file" || true

echo
echo "Package/Jasmine context clues:"
git ls-files | rg '(^package\.json$|^package-lock\.json$|^yarn\.lock$|^pnpm-lock\.yaml$)' || true
if [ -f package.json ]; then
  node -e 'const p=require("./package.json"); console.log(JSON.stringify({dependencies:p.dependencies, devDependencies:p.devDependencies}, null, 2))'
fi

Repository: parse-community/parse-server

Length of output: 11321


Replace these rejected-message assertions with toBeRejectedWithError() and await them.

toBeRejected() does not accept an expected argument, so Jasmine ignores these strings and the assertions would pass even if the controller emitted a different error text. Also invoke await expectAsync(...) so a non-rejection is reported as a failed spec rather than an unhandled rejection.

💚 Proposed fix
-      expectAsync(
+      await expectAsync(
         parseGraphQLController.updateGraphQLConfig({
           classConfigs: [
             {
               className,
               mutation: {
                 createMany: true,
                 createManyAlias: true,
               },
             },
           ],
         })
-      ).toBeRejected(
+      ).toBeRejectedWithError(
         `Invalid graphQLConfig: classConfig:${className} is invalid because "mutation.createManyAlias" must be a string`
       );

Apply the same change to the updateManyAlias and deleteManyAlias cases.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@spec/ParseGraphQLController.spec.js` around lines 1073 - 1119, Replace the
three toBeRejected assertions in the updateGraphQLConfig validation tests with
awaited expectAsync(...).toBeRejectedWithError() calls, preserving each expected
invalid-alias message for createManyAlias, updateManyAlias, and deleteManyAlias.

});
});
});
11 changes: 10 additions & 1 deletion spec/ParseGraphQLSchema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,16 @@ describe('ParseGraphQLSchema', () => {
expect(Object.keys(queries1).sort()).toEqual(Object.keys(queries2).sort());
expect(mutations1).not.toBe(mutations2);
expect(
Object.keys(mutations1).concat('createCars', 'updateCars', 'deleteCars').sort()
Object.keys(mutations1)
.concat(
'createCars',
'updateCars',
'deleteCars',
'createManyCars',
'updateManyCars',
'deleteManyCars'
)
.sort()
).toEqual(Object.keys(mutations2).sort());
});
});
Expand Down
Loading
Loading