Repository navigation
test(sdk): assert the request in generated service tests - #2114
Merged
Merged
Conversation
Generated PHP, Python, Dart and Flutter service tests mocked the client with wildcards and only checked the returned model, so a method calling the wrong verb or path, or dropping its body, still passed. Each test now pins the verb, the path with the example arguments substituted, and the parameter names the method sends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🟢 Tier S · Ready to mergeGenerated PHP, Python, Dart, and Flutter service tests now assert the request verb, substituted path, and parameter names in addition to the response. Generation tests check representative request assertions for each SDK family, including Python body parameters.
📂 Walkthrough · 5
Reviewed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Generated PHP, Python, Dart and Flutter service unit tests mocked the client with wildcards and only checked the returned model. A method that sent the wrong verb or path, or dropped its body, still passed. Hansi raised this on the
createQuerytests in appwrite/sdk-for-php#97, appwrite/sdk-for-python#166 and appwrite/sdk-for-dart#136, but the pattern covers every generated method.Each generated method test now checks:
->expects()->call('<VERB>', '<path>', Mockery::any(), Mockery::on(...)). The closure checksarray_keys($params)withassertSame.MockeryPHPUnitIntegrationmakesexpects()verify that the call happened exactly once.requests_mockmatches only the method's verb. The test checksm.last_requestagainst the unquoted URL path and the names of the parameters sent: the JSON body keys, the query keys for GET, or the multipart field names for uploads.MockClient.callandchunkedUploadnow includepath,paramsand the other named arguments in theInvocation. The test then runsverify(client.call(HttpMethod.x, path: '<path>', params: captureAnyNamed('params'), ...))and checksparams.keys. For webAuth methods, the test checks the decoded URL path.The expected path is the spec path with the example arguments substituted. Config-filled path parameters, such as
oauth2/{project_id}, take the test client's config value, which is the SDK's real behaviour.Evidence
New Generation test fails before and passes after.
GenerationTest::testServiceTestsAssertTheRequesthas 9 cases: path and params for PHP, Python, Dart and Flutter, plus Python body.Tests: 9, Assertions: 9, Failures: 9.OK (9 tests, 9 assertions)Mutation check. I mutated
Foo::put()in each generated fixture SDK and ran only that method's generated test:Foo.put()/mock/tests/bar/mock/tests/bar/mock/tests/barDart already caught a wrong verb because its stub was verb-specific. It missed wrong paths and dropped bodies.
Generated tests pass on the real Appwrite 2.4.x spec (server, generated locally):
OK (945 tests, 2765 assertions)Ran 884 tests ... OK, andblack --checkpasses+804: All tests passed!On the fixture, PHP, Python and Dart each pass 56 tests. The fixture includes the
grant/special&idpath argument and the multipart uploads.Known limits
Python's query string and multipart encoding drop the empty
[]/{}arguments the tests pass. For GET and upload methods, the expected names therefore leave out required array and object parameters. JSON bodies still list them.🤖 Generated with Claude Code