-
Notifications
You must be signed in to change notification settings - Fork 196
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 4 commits
e8d7b7b
58da2df
de86471
a85d92f
72731b6
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| const { ID } = require("../dist/id"); | ||
|
|
||
| describe("ID", () => { | ||
| test('unique', () => expect(ID.unique()).toHaveLength(20)); | ||
| test('custom', () => expect(ID.custom('custom')).toEqual('custom')); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| const { Condition, Operator } = require("../dist/operator"); | ||
|
|
||
| describe('Operator', () => { | ||
| test('returns increment', () => { | ||
| expect(Operator.increment(1)).toEqual(`{"method":"increment","values":[1]}`); | ||
| }); | ||
|
|
||
| test('returns increment with max', () => { | ||
| expect(Operator.increment(5, 100)).toEqual(`{"method":"increment","values":[5,100]}`); | ||
| }); | ||
|
|
||
| test('returns decrement', () => { | ||
| expect(Operator.decrement(1)).toEqual(`{"method":"decrement","values":[1]}`); | ||
| }); | ||
|
|
||
| test('returns decrement with min', () => { | ||
| expect(Operator.decrement(3, 0)).toEqual(`{"method":"decrement","values":[3,0]}`); | ||
| }); | ||
|
|
||
| test('returns multiply', () => { | ||
| expect(Operator.multiply(2)).toEqual(`{"method":"multiply","values":[2]}`); | ||
| }); | ||
|
|
||
| test('returns multiply with max', () => { | ||
| expect(Operator.multiply(3, 1000)).toEqual(`{"method":"multiply","values":[3,1000]}`); | ||
| }); | ||
|
|
||
| test('returns divide', () => { | ||
| expect(Operator.divide(2)).toEqual(`{"method":"divide","values":[2]}`); | ||
| }); | ||
|
|
||
| test('returns divide with min', () => { | ||
| expect(Operator.divide(4, 1)).toEqual(`{"method":"divide","values":[4,1]}`); | ||
| }); | ||
|
|
||
| test('returns modulo', () => { | ||
| expect(Operator.modulo(5)).toEqual(`{"method":"modulo","values":[5]}`); | ||
| }); | ||
|
|
||
| test('returns power', () => { | ||
| expect(Operator.power(2)).toEqual(`{"method":"power","values":[2]}`); | ||
| }); | ||
|
|
||
| test('returns arrayAppend', () => { | ||
| expect(Operator.arrayAppend(['item1', 'item2'])).toEqual('{"method":"arrayAppend","values":["item1","item2"]}'); | ||
| }); | ||
|
|
||
| test('returns arrayPrepend', () => { | ||
| expect(Operator.arrayPrepend(['first', 'second'])).toEqual('{"method":"arrayPrepend","values":["first","second"]}'); | ||
| }); | ||
|
|
||
| test('returns arrayInsert', () => { | ||
| expect(Operator.arrayInsert(0, 'newItem')).toEqual('{"method":"arrayInsert","values":[0,"newItem"]}'); | ||
| }); | ||
|
|
||
| test('returns arrayRemove', () => { | ||
| expect(Operator.arrayRemove('oldItem')).toEqual('{"method":"arrayRemove","values":["oldItem"]}'); | ||
| }); | ||
|
|
||
| test('returns arrayUnique', () => { | ||
| expect(Operator.arrayUnique()).toEqual('{"method":"arrayUnique","values":[]}'); | ||
| }); | ||
|
|
||
| test('returns arrayIntersect', () => { | ||
| expect(Operator.arrayIntersect(['a', 'b', 'c'])).toEqual('{"method":"arrayIntersect","values":["a","b","c"]}'); | ||
| }); | ||
|
|
||
| test('returns arrayDiff', () => { | ||
| expect(Operator.arrayDiff(['x', 'y'])).toEqual('{"method":"arrayDiff","values":["x","y"]}'); | ||
| }); | ||
|
|
||
| test('returns arrayFilter', () => { | ||
| expect(Operator.arrayFilter(Condition.Equal, 'test')).toEqual('{"method":"arrayFilter","values":["equal","test"]}'); | ||
| }); | ||
|
|
||
| test('returns stringConcat', () => { | ||
| expect(Operator.stringConcat('suffix')).toEqual('{"method":"stringConcat","values":["suffix"]}'); | ||
| }); | ||
|
|
||
| test('returns stringReplace', () => { | ||
| expect(Operator.stringReplace('old', 'new')).toEqual('{"method":"stringReplace","values":["old","new"]}'); | ||
| }); | ||
|
|
||
| test('returns toggle', () => { | ||
| expect(Operator.toggle()).toEqual('{"method":"toggle","values":[]}'); | ||
| }); | ||
|
|
||
| test('returns dateAddDays', () => { | ||
| expect(Operator.dateAddDays(7)).toEqual('{"method":"dateAddDays","values":[7]}'); | ||
| }); | ||
|
|
||
| test('returns dateSubDays', () => { | ||
| expect(Operator.dateSubDays(7)).toEqual('{"method":"dateSubDays","values":[7]}'); | ||
| }); | ||
|
|
||
| test('returns dateSetNow', () => { | ||
| expect(Operator.dateSetNow()).toEqual('{"method":"dateSetNow","values":[]}'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| const { Permission } = require("../dist/permission"); | ||
| const { Role } = require("../dist/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("../dist/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(`{"method":"equal","attribute":"attr","values":${t.expectedValues}}`) | ||
| ) | ||
| } | ||
| }) | ||
|
|
||
| describe('basic filter notEqual', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.notEqual("attr", t.value)) | ||
| .toEqual(`{"method":"notEqual","attribute":"attr","values":${t.expectedValues}}`) | ||
| ) | ||
| } | ||
| }); | ||
|
|
||
| describe('basic filter lessThan', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.lessThan("attr", t.value)) | ||
| .toEqual(`{"method":"lessThan","attribute":"attr","values":${t.expectedValues}}`) | ||
| ) | ||
| } | ||
| }); | ||
|
|
||
| describe('basic filter lessThanEqual', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.lessThanEqual("attr", t.value)) | ||
| .toEqual(`{"method":"lessThanEqual","attribute":"attr","values":${t.expectedValues}}`) | ||
| ) | ||
| } | ||
| }); | ||
|
|
||
| describe('basic filter greaterThan', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.greaterThan("attr", t.value)) | ||
| .toEqual(`{"method":"greaterThan","attribute":"attr","values":${t.expectedValues}}`) | ||
| ) | ||
| } | ||
| }); | ||
|
|
||
| describe('basic filter greaterThanEqual', () => { | ||
| for (const t of tests) { | ||
| test(t.description, () => | ||
| expect(Query.greaterThanEqual("attr", t.value)) | ||
| .toEqual(`{"method":"greaterThanEqual","attribute":"attr","values":${t.expectedValues}}`) | ||
| ) | ||
| } | ||
| }); | ||
|
|
||
| test('search', () => | ||
| expect(Query.search('attr', 'keyword1 keyword2')) | ||
| .toEqual(`{"method":"search","attribute":"attr","values":["keyword1 keyword2"]}`) | ||
| ); | ||
|
|
||
| test('isNull', () => | ||
| expect(Query.isNull('attr')) | ||
| .toEqual(`{"method":"isNull","attribute":"attr"}`) | ||
| ); | ||
|
|
||
| test('isNotNull', () => | ||
| expect(Query.isNotNull('attr')) | ||
| .toEqual(`{"method":"isNotNull","attribute":"attr"}`) | ||
| ); | ||
|
|
||
| describe('between', () => { | ||
| test('with integers', () => | ||
| expect(Query.between('attr', 1, 2)) | ||
| .toEqual(`{"method":"between","attribute":"attr","values":[1,2]}`) | ||
| ); | ||
| test('with doubles', () => | ||
| expect(Query.between('attr', 1.2, 2.2)) | ||
| .toEqual(`{"method":"between","attribute":"attr","values":[1.2,2.2]}`) | ||
| ); | ||
| test('with strings', () => | ||
| expect(Query.between('attr',"a","z")) | ||
| .toEqual(`{"method":"between","attribute":"attr","values":["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(`{"method":"select","values":["attr1","attr2"]}`) | ||
| ); | ||
|
|
||
| test('orderAsc', () => | ||
| expect(Query.orderAsc('attr')) | ||
| .toEqual(`{"method":"orderAsc","attribute":"attr"}`) | ||
| ); | ||
|
|
||
| test('orderDesc', () => | ||
| expect(Query.orderDesc('attr')) | ||
| .toEqual(`{"method":"orderDesc","attribute":"attr"}`) | ||
| ); | ||
|
|
||
| test('cursorBefore', () => | ||
| expect(Query.cursorBefore('attr')) | ||
| .toEqual('{"method":"cursorBefore","values":["attr"]}') | ||
| ); | ||
|
|
||
| test('cursorAfter', () => | ||
| expect(Query.cursorAfter('attr')) | ||
| .toEqual('{"method":"cursorAfter","values":["attr"]}') | ||
| ); | ||
|
|
||
| test('limit', () => | ||
| expect(Query.limit(1)) | ||
| .toEqual('{"method":"limit","values":[1]}') | ||
| ); | ||
|
|
||
| test('offset', () => | ||
| expect(Query.offset(1)) | ||
| .toEqual('{"method":"offset","values":[1]}') | ||
| ); | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| const { Role } = require("../dist/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')) | ||
| }) |
Uh oh!
There was an error while loading. Please reload this page.