-
Notifications
You must be signed in to change notification settings - Fork 197
Unit Tests - Node #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Unit Tests - Node #736
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| namespace Appwrite\SDK\Language; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class Node extends Web | ||||||||||||||||||||||
| class Node extends JS | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * @return string | ||||||||||||||||||||||
|
|
@@ -145,21 +145,41 @@ public function getFiles(): array | |||||||||||||||||||||
| 'destination' => 'src/models.ts', | ||||||||||||||||||||||
| 'template' => 'web/src/models.ts.twig', | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| [ | ||||||||||||||||||||||
| 'scope' => 'default', | ||||||||||||||||||||||
| 'destination' => 'test/permission.test.js', | ||||||||||||||||||||||
| 'template' => 'node/test/permission.test.js.twig', | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| [ | ||||||||||||||||||||||
| 'scope' => 'default', | ||||||||||||||||||||||
| 'destination' => 'src/permission.ts', | ||||||||||||||||||||||
| 'template' => 'web/src/permission.ts.twig', | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| [ | ||||||||||||||||||||||
| 'scope' => 'default', | ||||||||||||||||||||||
| 'destination' => 'test/role.test.js', | ||||||||||||||||||||||
| 'template' => 'node/test/role.test.js.twig', | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| [ | ||||||||||||||||||||||
| 'scope' => 'default', | ||||||||||||||||||||||
| 'destination' => 'src/role.ts', | ||||||||||||||||||||||
| 'template' => 'web/src/role.ts.twig', | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| [ | ||||||||||||||||||||||
| 'scope' => 'default', | ||||||||||||||||||||||
| 'destination' => 'test/id.test.js', | ||||||||||||||||||||||
| 'template' => 'node/test/id.test.js.twig', | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| [ | ||||||||||||||||||||||
| 'scope' => 'default', | ||||||||||||||||||||||
| 'destination' => 'src/id.ts', | ||||||||||||||||||||||
| 'template' => 'web/src/id.ts.twig', | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| [ | ||||||||||||||||||||||
| 'scope' => 'default', | ||||||||||||||||||||||
| 'destination' => 'test/query.test.js', | ||||||||||||||||||||||
| 'template' => 'node/test/query.test.js.twig', | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| [ | ||||||||||||||||||||||
| 'scope' => 'default', | ||||||||||||||||||||||
| 'destination' => 'src/query.ts', | ||||||||||||||||||||||
|
|
@@ -170,6 +190,11 @@ public function getFiles(): array | |||||||||||||||||||||
| 'destination' => 'src/operator.ts', | ||||||||||||||||||||||
| 'template' => 'node/src/operator.ts.twig', | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| [ | ||||||||||||||||||||||
| 'scope' => 'service', | ||||||||||||||||||||||
| 'destination' => '/test/services/{{service.name | caseDash}}.test.js', | ||||||||||||||||||||||
| 'template' => 'node/test/services/service.test.js.twig', | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
|
Comment on lines
+193
to
+197
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leading slash in destination path is inconsistent. Line 195 has Proposed fix [
'scope' => 'service',
- 'destination' => '/test/services/{{service.name | caseDash}}.test.js',
+ 'destination' => 'test/services/{{service.name | caseDash}}.test.js',
'template' => 'node/test/services/service.test.js.twig',
],📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| [ | ||||||||||||||||||||||
| 'scope' => 'default', | ||||||||||||||||||||||
| 'destination' => 'README.md', | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| const ID = require("../lib/id"); | ||
|
|
||
| describe("ID", () => { | ||
| test('unique', () => expect(ID.unique()).toEqual('unique()')); | ||
| test('custom', () => expect(ID.custom('custom')).toEqual('custom')); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| const Permission = require("../lib/permission"); | ||
| const Role = require("../lib/role"); | ||
|
|
||
| describe('Permission', () => { | ||
| test('read', () => expect(Permission.read(Role.any())).toEqual('read("any")')); | ||
| test('write', () => expect(Permission.write(Role.any())).toEqual('write("any")')); | ||
| test('create', () => expect(Permission.create(Role.any())).toEqual('create("any")')); | ||
| test('update', () => expect(Permission.update(Role.any())).toEqual('update("any")')); | ||
| test('delete', () => expect(Permission.delete(Role.any())).toEqual('delete("any")')); | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| const Query = require("../lib/query"); | ||
|
|
||
| const tests = [ | ||
| { | ||
| description: 'with a string', | ||
| value: 's', | ||
| expectedValues: '["s"]' | ||
| }, | ||
| { | ||
| description: 'with a integer', | ||
| value: 1, | ||
| expectedValues: '[1]' | ||
| }, | ||
| { | ||
| description: 'with a double', | ||
| value: 1.2, | ||
| expectedValues: '[1.2]' | ||
| }, | ||
| { | ||
| description: 'with a whole number double', | ||
| value: 1.0, | ||
| expectedValues: '[1]' | ||
| }, | ||
| { | ||
| description: 'with a bool', | ||
| value: false, | ||
| expectedValues: '[false]' | ||
| }, | ||
| { | ||
| description: 'with a list', | ||
| value: ['a', 'b', 'c'], | ||
| expectedValues: '["a","b","c"]' | ||
| } | ||
| ]; | ||
|
|
||
| describe('Query', () => { | ||
| describe('basic filter equal', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.equal("attr", t.value)) | ||
| .toEqual(`equal("attr", ${t.expectedValues})`) | ||
| ) | ||
| } | ||
| }) | ||
|
|
||
| describe('basic filter notEqual', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.notEqual("attr", t.value)) | ||
| .toEqual(`notEqual("attr", ${t.expectedValues})`) | ||
| ) | ||
| } | ||
| }); | ||
|
|
||
| describe('basic filter lessThan', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.lessThan("attr", t.value)) | ||
| .toEqual(`lessThan("attr", ${t.expectedValues})`) | ||
| ) | ||
| } | ||
| }); | ||
|
|
||
| describe('basic filter lessThanEqual', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.lessThanEqual("attr", t.value)) | ||
| .toEqual(`lessThanEqual("attr", ${t.expectedValues})`) | ||
| ) | ||
| } | ||
| }); | ||
|
|
||
| describe('basic filter greaterThan', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.greaterThan("attr", t.value)) | ||
| .toEqual(`greaterThan("attr", ${t.expectedValues})`) | ||
| ) | ||
| } | ||
| }); | ||
|
|
||
| describe('basic filter greaterThanEqual', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.greaterThanEqual("attr", t.value)) | ||
| .toEqual(`greaterThanEqual("attr", ${t.expectedValues})`) | ||
| ) | ||
| } | ||
| }); | ||
|
|
||
| test('search', () => | ||
| expect(Query.search('attr', 'keyword1 keyword2')) | ||
| .toEqual('search("attr", ["keyword1 keyword2"])') | ||
| ); | ||
|
|
||
| test('isNull', () => | ||
| expect(Query.isNull('attr')) | ||
| .toEqual('isNull("attr")') | ||
| ); | ||
|
|
||
| test('isNotNull', () => | ||
| expect(Query.isNotNull('attr')) | ||
| .toEqual('isNotNull("attr")') | ||
| ); | ||
|
|
||
| describe('between', () => { | ||
| test('with integers', () => | ||
| expect(Query.between('attr', 1, 2)) | ||
| .toEqual('between("attr", 1, 2)') | ||
| ); | ||
| test('with doubles', () => | ||
| expect(Query.between('attr', 1.2, 2.2)) | ||
| .toEqual('between("attr", 1.2, 2.2)') | ||
| ); | ||
| test('with strings', () => | ||
| expect(Query.between('attr', "a", "z")) | ||
| .toEqual('between("attr", "a" "z")') | ||
| ); | ||
|
Comment on lines
+115
to
+118
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check Query.between implementation for string handling
fd -e ts -e js "query" templates/web/src templates/node/src --exec cat {}Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: find . -type f -name "*.ts" -o -name "*.js" -o -name "*.twig" | xargs grep -l "between.*attr" | head -20Repository: appwrite/sdk-generator Length of output: 713 🏁 Script executed: fd -type f "query" --extension ts --extension js --extension twigRepository: appwrite/sdk-generator Length of output: 236 🏁 Script executed: rg "between\(" --type ts --type js -A 3 -B 3 | head -50Repository: appwrite/sdk-generator Length of output: 2126 🏁 Script executed: cat templates/web/src/query.ts.twigRepository: appwrite/sdk-generator Length of output: 17362 🏁 Script executed: cat templates/node/src/query.ts.twigRepository: appwrite/sdk-generator Length of output: 130 🏁 Script executed: cat templates/node/test/query.test.js.twig | head -130Repository: appwrite/sdk-generator Length of output: 3606 🏁 Script executed: find . -name "query.js" -o -name "query.ts" | grep -E "(lib|dist)" | head -10Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: rg "between.*function\|between.*=>" --type ts --type js -A 5 -B 2 | head -80Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: find templates -name "*query*" -type f | grep nodeRepository: appwrite/sdk-generator Length of output: 104 🏁 Script executed: cat templates/node/lib/query.js.twigRepository: appwrite/sdk-generator Length of output: 130 🏁 Script executed: find templates -type f -name "*query*"Repository: appwrite/sdk-generator Length of output: 434 🏁 Script executed: cat templates/web/src/query.ts.twig | grep -A 30 "between"Repository: appwrite/sdk-generator Length of output: 4242 🏁 Script executed: cat templates/deno/src/query.ts.twig | head -60Repository: appwrite/sdk-generator Length of output: 1919 🏁 Script executed: rg "node.*query\|query.*node" --type json --type yaml --type toml | head -20Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: find . -name "*.json" -o -name "*.yaml" -o -name "*.yml" | xargs grep -l "node\|query" 2>/dev/null | head -10Repository: appwrite/sdk-generator Length of output: 404 🏁 Script executed: cat package.json 2>/dev/null | head -50Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: find . -name "README*" -o -name "*.md" | xargs grep -l "query\|generate" 2>/dev/null | head -5Repository: appwrite/sdk-generator Length of output: 182 🏁 Script executed: cat README.md | head -100Repository: appwrite/sdk-generator Length of output: 4009 🏁 Script executed: ls -la | grep -E "config|generate|spec"Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: find . -name "*.php" -o -name "*.py" -o -name "*.js" | xargs grep -l "between.*format\|query.*format" 2>/dev/null | head -10Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: rg "toString|format" templates/node/test/query.test.js.twig -A 2 -B 2Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: rg "between\(" tests/languages/ -A 1 -B 1Repository: appwrite/sdk-generator Length of output: 6594 🏁 Script executed: cat tests/languages/node/test.js | grep -A 5 -B 5 "between"Repository: appwrite/sdk-generator Length of output: 693 🏁 Script executed: find . -path "*node*" -name "*.js" -o -path "*node*" -name "*.ts" | xargs grep -l "class Query\|function Query" 2>/dev/null | head -10Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: rg "toString\(\)" templates/ --type ts --type js -B 10 | grep -A 10 "between"Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: cat tests/languages/node/test.js | head -50Repository: appwrite/sdk-generator Length of output: 1235 🏁 Script executed: find . -name "dist" -o -name "build" -o -name "examples" | head -10Repository: appwrite/sdk-generator Length of output: 116 🏁 Script executed: find . -path "*examples*" -name "*query*" -type f | head -10Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: cat templates/node/test/query.test.js.twig | sed -n '100,130p'Repository: appwrite/sdk-generator Length of output: 920 🏁 Script executed: find . -name "*.php" | xargs grep -l "class Query\|function between" 2>/dev/null | head -5Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: rg "between.*attr.*a.*z" --type js --type ts --type phpRepository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: cat src/SDK/Language/Node.php 2>/dev/null | head -100Repository: appwrite/sdk-generator Length of output: 2867 🏁 Script executed: cat src/SDK/Language/JS.php | head -200Repository: appwrite/sdk-generator Length of output: 5309 🏁 Script executed: rg "between.*format\|query.*method\|toString" src/SDK/Language/JS.php -A 5 -B 5Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: cat templates/node/test/query.test.js.twig | grep -A 200 "describe.*between" | head -50Repository: appwrite/sdk-generator Length of output: 1367 🏁 Script executed: rg "between\|Query\." templates/node/test/query.test.js.twig | head -30Repository: appwrite/sdk-generator Length of output: 48 🏁 Script executed: cat templates/node/test/query.test.js.twigRepository: appwrite/sdk-generator Length of output: 4172 🏁 Script executed: find . -name "*.twig" -path "*query*" | xargs grep -l "between\|method" | head -10Repository: appwrite/sdk-generator Length of output: 454 🏁 Script executed: cat templates/node/src/query.js.twig 2>/dev/null || cat templates/node/src/query.ts.twig 2>/dev/null || find templates/node -name "*.twig" -type fRepository: appwrite/sdk-generator Length of output: 783 🏁 Script executed: rg "class Query|between" templates/ -A 10 -B 2 | grep -A 10 "between" | head -50Repository: appwrite/sdk-generator Length of output: 3237 Fix missing comma in Line 117 expects Current code (lines 115-118)🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| test('select', () => | ||
| expect(Query.select(['attr1', 'attr2'])) | ||
| .toEqual('select(["attr1","attr2"])') | ||
| ); | ||
|
|
||
| test('orderAsc', () => | ||
| expect(Query.orderAsc('attr')) | ||
| .toEqual('orderAsc("attr")') | ||
| ); | ||
|
|
||
| test('orderDesc', () => | ||
| expect(Query.orderDesc('attr')) | ||
| .toEqual('orderDesc("attr")') | ||
| ); | ||
|
|
||
| test('cursorBefore', () => | ||
| expect(Query.cursorBefore('attr')) | ||
| .toEqual('cursorBefore("attr")') | ||
| ); | ||
|
|
||
| test('cursorAfter', () => | ||
| expect(Query.cursorAfter('attr')) | ||
| .toEqual('cursorAfter("attr")') | ||
| ); | ||
|
|
||
| test('limit', () => | ||
| expect(Query.limit(1)) | ||
| .toEqual('limit(1)') | ||
| ); | ||
|
|
||
| test('offset', () => | ||
| expect(Query.offset(1)) | ||
| .toEqual('offset(1)') | ||
| ); | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| const Role = require("../lib/role"); | ||
|
|
||
| describe('Role', () => { | ||
| test('any', () => expect(Role.any()).toEqual('any')); | ||
| test('user without status', () => expect(Role.user('custom')).toEqual('user:custom')); | ||
| test('user with status', () => expect(Role.user('custom', 'verified')).toEqual('user:custom/verified')); | ||
| test('users without status', () => expect(Role.users()).toEqual('users')); | ||
| test('users with status', () => expect(Role.users('verified')).toEqual('users/verified')); | ||
| test('guests', () => expect(Role.guests()).toEqual('guests')); | ||
| test('team without role', () => expect(Role.team('custom')).toEqual('team:custom')) | ||
| test('team with role', () => expect(Role.team('custom', 'owner')).toEqual('team:custom/owner')) | ||
| test('member', () => expect(Role.member('custom')).toEqual('member:custom')) | ||
| test('label', () => expect(Role.label('admin')).toEqual('label:admin')) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| const Client = require("../../lib/client"); | ||
| const InputFile = require("../../lib/inputFile"); | ||
| const {{ service.name | caseUcfirst }} = require("../../lib/services/{{ service.name | caseCamel }}"); | ||
|
|
||
| const mockedAxios = require("axios"); | ||
| jest.mock('axios', () => jest.fn()); | ||
loks0n marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| describe('{{ service.name | caseUcfirst }}', () => { | ||
| const client = new Client(); | ||
| const {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client); | ||
|
|
||
| {% for method in service.methods ~%} | ||
| test('test method {{ method.name | caseCamel }}()', async () => { | ||
| {%~ if method.type == 'webAuth' %} | ||
| const data = ''; | ||
| {%~ elseif method.type == 'location' %} | ||
| const data = new Uint8Array(0); | ||
| {%~ else %} | ||
| {%- if method.responseModel and method.responseModel != 'any' %} | ||
| const data = { | ||
| {%- for definition in spec.definitions ~%}{%~ if definition.name == method.responseModel -%}{%~ for property in definition.properties | filter((param) => param.required) ~%} | ||
| '{{ property.name | escapeDollarSign }}': {% if property.type == 'object' %}{}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}'{{ property.example | escapeDollarSign }}'{% elseif property.type == 'boolean' %}true{% else %}{{ property.example }}{% endif %},{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor -%} | ||
| }; | ||
| {%~ else %} | ||
| const data = ''; | ||
| {%~ endif %} | ||
| {%~ endif %} | ||
|
|
||
| mockedAxios.mockImplementation(() => Promise.resolve({data: data})); | ||
|
|
||
| const response = await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({%~ for parameter in method.parameters.all | filter((param) => param.required) ~%} | ||
| {% if parameter.type == 'object' %}{}{% elseif parameter.type == 'array' %}[]{% elseif parameter.type == 'file' %}InputFile.fromBuffer(new Uint8Array(0), 'image.png'){% elseif parameter.type == 'boolean' %}true{% elseif parameter.type == 'string' %}'{% if parameter.example is not empty %}{{ parameter.example | escapeDollarSign }}{% endif %}'{% elseif parameter.type == 'integer' and parameter['x-example'] is empty %}1{% elseif parameter.type == 'number' and parameter['x-example'] is empty %}1.0{% else %}{{ parameter.example }}{%~ endif ~%},{%~ endfor ~%} | ||
| ); | ||
|
|
||
| expect(response).toEqual(data); | ||
| }); | ||
| {% endfor %} | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: appwrite/sdk-generator
Length of output: 50378
🏁 Script executed:
Repository: appwrite/sdk-generator
Length of output: 2742
🏁 Script executed:
Repository: appwrite/sdk-generator
Length of output: 2767
🏁 Script executed:
Repository: appwrite/sdk-generator
Length of output: 5041
🏁 Script executed:
Repository: appwrite/sdk-generator
Length of output: 48
🏁 Script executed:
Repository: appwrite/sdk-generator
Length of output: 5863
🏁 Script executed:
Repository: appwrite/sdk-generator
Length of output: 12341
Node.php cannot extend JS without also providing Web's Twig filters.
Node templates require filters (
getPropertyType,getReturn,getGenerics,getOverloadCondition, etc.) that are defined in Web.php'sgetFilters()method. Since JS.php only defines basic filters and Node doesn't overridegetFilters(), extending JS directly will break Node SDK generation with missing filter errors.Additionally, line 195 has an inconsistent leading slash in the destination path (
'/test/services/...') compared to other entries like line 189 ('test/permission.test.js') and line 229 (template path/node/tsconfig.json.twigalso inconsistent with other templates).Either restore Node to extend Web, or add the missing filter definitions to Node's
getFilters()method. Also standardize the leading slashes in destination paths.🤖 Prompt for AI Agents