Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 1.5.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/SDK/Language/PHP.php
  • Loading branch information
abnegate committed Jan 17, 2024
2 parents 6c7e374 + 9ed91ce commit 2e3d7b7
Show file tree
Hide file tree
Showing 16 changed files with 610 additions and 10 deletions.
25 changes: 25 additions & 0 deletions src/SDK/Language/Deno.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,41 @@ public function getFiles(): array
'destination' => 'src/permission.ts',
'template' => 'deno/src/permission.ts.twig',
],
[
'scope' => 'default',
'destination' => 'test/permission.test.ts',
'template' => 'deno/test/permission.test.ts.twig',
],
[
'scope' => 'default',
'destination' => 'src/role.ts',
'template' => 'deno/src/role.ts.twig',
],
[
'scope' => 'default',
'destination' => 'test/role.test.ts',
'template' => 'deno/test/role.test.ts.twig',
],
[
'scope' => 'default',
'destination' => 'src/id.ts',
'template' => 'deno/src/id.ts.twig',
],
[
'scope' => 'default',
'destination' => 'test/id.test.ts',
'template' => 'deno/test/id.test.ts.twig',
],
[
'scope' => 'default',
'destination' => 'src/query.ts',
'template' => 'deno/src/query.ts.twig',
],
[
'scope' => 'default',
'destination' => 'test/query.test.ts',
'template' => 'deno/test/query.test.ts.twig',
],
[
'scope' => 'default',
'destination' => 'src/inputFile.ts',
Expand All @@ -75,6 +95,11 @@ public function getFiles(): array
'destination' => '/src/services/{{service.name | caseDash}}.ts',
'template' => 'deno/src/services/service.ts.twig',
],
[
'scope' => 'service',
'destination' => '/test/services/{{service.name | caseDash}}.test.ts',
'template' => 'deno/test/services/service.test.ts.twig',
],
[
'scope' => 'default',
'destination' => 'README.md',
Expand Down
25 changes: 25 additions & 0 deletions src/SDK/Language/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,41 @@ public function getFiles(): array
'destination' => 'src/{{ spec.title | caseUcfirst}}/Permission.php',
'template' => 'php/src/Permission.php.twig',
],
[
'scope' => 'default',
'destination' => 'tests/{{ spec.title | caseUcfirst}}/PermissionTest.php',
'template' => 'php/tests/PermissionTest.php.twig',
],
[
'scope' => 'default',
'destination' => 'src/{{ spec.title | caseUcfirst}}/Role.php',
'template' => 'php/src/Role.php.twig',
],
[
'scope' => 'default',
'destination' => 'tests/{{ spec.title | caseUcfirst}}/RoleTest.php',
'template' => 'php/tests/RoleTest.php.twig',
],
[
'scope' => 'default',
'destination' => 'src/{{ spec.title | caseUcfirst}}/ID.php',
'template' => 'php/src/ID.php.twig',
],
[
'scope' => 'default',
'destination' => 'tests/{{ spec.title | caseUcfirst}}/IDTest.php',
'template' => 'php/tests/IDTest.php.twig',
],
[
'scope' => 'default',
'destination' => 'src/{{ spec.title | caseUcfirst}}/Query.php',
'template' => 'php/src/Query.php.twig',
],
[
'scope' => 'default',
'destination' => 'tests/{{ spec.title | caseUcfirst}}/QueryTest.php',
'template' => 'php/tests/QueryTest.php.twig',
],
[
'scope' => 'default',
'destination' => 'src/{{ spec.title | caseUcfirst}}/InputFile.php',
Expand All @@ -212,6 +232,11 @@ public function getFiles(): array
'destination' => '/src/{{ spec.title | caseUcfirst}}/Services/{{service.name | caseUcfirst}}.php',
'template' => 'php/src/Services/Service.php.twig',
],
[
'scope' => 'service',
'destination' => '/tests/{{ spec.title | caseUcfirst}}/Services/{{service.name | caseUcfirst}}Test.php',
'template' => 'php/tests/Services/ServiceTest.php.twig',
],
[
'scope' => 'enum',
'destination' => '/src/{{ spec.title | caseUcfirst}}/Enums/{{ enum.name | caseUcfirst }}.php',
Expand Down
12 changes: 6 additions & 6 deletions templates/deno/src/exception.ts.twig
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export class {{ spec.title | caseUcfirst}}Exception {
message: String;
code: Number;
message: string;
code: number;
response: any;
type: String;
type: string;

constructor(message: String, code: Number = 0, type: String = "", response: any = "") {
constructor(message: string, code: number = 0, type: string = "", response: any = "") {
this.message = message;
this.code = code;
this.type = type;
this.response = response;
}

public toString(): String {
public toString(): string {
return `${this.message} - ${this.code} - ${this.type} - ${JSON.stringify(this.response)}`;
}
}
}
8 changes: 8 additions & 0 deletions templates/deno/test/id.test.ts.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {assertEquals} from "https://deno.land/[email protected]/assert/mod.ts";
import {describe, it as test} from "https://deno.land/[email protected]/testing/bdd.ts";
import {ID} from "../src/id.ts";

describe("ID", () => {
test('unique', () => assertEquals(ID.unique(), 'unique()'));
test('custom', () => assertEquals(ID.custom('custom'), 'custom'));
});
12 changes: 12 additions & 0 deletions templates/deno/test/permission.test.ts.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";
import { describe, it as test } from "https://deno.land/[email protected]/testing/bdd.ts";
import {Permission} from "../src/permission.ts";
import {Role} from "../src/role.ts";

describe('Permission', () => {
test('read', () => assertEquals(Permission.read(Role.any()), 'read("any")'));
test('write', () => assertEquals(Permission.write(Role.any()), 'write("any")'));
test('create', () => assertEquals(Permission.create(Role.any()), 'create("any")'));
test('update', () => assertEquals(Permission.update(Role.any()), 'update("any")'));
test('delete', () => assertEquals(Permission.delete(Role.any()), 'delete("any")'));
})
175 changes: 175 additions & 0 deletions templates/deno/test/query.test.ts.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import {describe, it as test} from "https://deno.land/[email protected]/testing/bdd.ts";
import {assertEquals} from "https://deno.land/[email protected]/assert/assert_equals.ts";
import {Query, QueryTypes} from "../src/query.ts";

type BasicFilterQueryTest = {
description: string;
value: QueryTypes;
expectedValues: string;
}

const tests: BasicFilterQueryTest[] = [
{
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, () =>
assertEquals(
Query.equal("attr", t.value),
`equal("attr", ${t.expectedValues})`,
)
)
}
})

describe('basic filter notEqual', () => {
for (const t of tests) {
test(t.description, () =>
assertEquals(
Query.notEqual("attr", t.value),
`notEqual("attr", ${t.expectedValues})`,
)
)
}
});

describe('basic filter lessThan', () => {
for (const t of tests) {
test(t.description, () =>
assertEquals(
Query.lessThan("attr", t.value),
`lessThan("attr", ${t.expectedValues})`,
)
)
}
});

describe('basic filter lessThanEqual', () => {
for (const t of tests) {
test(t.description, () =>
assertEquals(
Query.lessThanEqual("attr", t.value),
`lessThanEqual("attr", ${t.expectedValues})`,
)
)
}
});

describe('basic filter greaterThan', () => {
for (const t of tests) {
test(t.description, () =>
assertEquals(
Query.greaterThan("attr", t.value),
`greaterThan("attr", ${t.expectedValues})`,
)
)
}
});

describe('basic filter greaterThanEqual', () => {
for (const t of tests) {
test(t.description, () =>
assertEquals(
Query.greaterThanEqual("attr", t.value),
`greaterThanEqual("attr", ${t.expectedValues})`,
)
)
}
});

test('search', () => assertEquals(
Query.search('attr', 'keyword1 keyword2'),
'search("attr", ["keyword1 keyword2"])',
));

test('isNull', () => assertEquals(
Query.isNull('attr'),
'isNull("attr")',
));

test('isNotNull', () => assertEquals(
Query.isNotNull('attr'),
'isNotNull("attr")',
));

describe('between', () => {
test('with integers', () => assertEquals(
Query.between('attr', 1, 2),
'between("attr", 1, 2)'
));
test('with doubles', () => assertEquals(
Query.between('attr', 1.2, 2.2),
'between("attr", 1.2, 2.2)'
));
test('with strings', () => assertEquals(
Query.between('attr', "a", "z"),
'between("attr", "a", "z")'
));
});

test('select', () => assertEquals(
Query.select(['attr1', 'attr2']),
'select(["attr1","attr2"])',
));

test('orderAsc', () => assertEquals(
Query.orderAsc('attr'),
'orderAsc("attr")',
));

test('orderDesc', () => assertEquals(
Query.orderDesc('attr'),
'orderDesc("attr")',
));

test('cursorBefore', () => assertEquals(
Query.cursorBefore('attr'),
'cursorBefore("attr")',
));

test('cursorAfter', () => assertEquals(
Query.cursorAfter('attr'),
'cursorAfter("attr")',
));

test('limit', () => assertEquals(
Query.limit(1),
'limit(1)'
));

test('offset', () => assertEquals(
Query.offset(1),
'offset(1)'
));
})
16 changes: 16 additions & 0 deletions templates/deno/test/role.test.ts.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";
import { describe, it as test } from "https://deno.land/[email protected]/testing/bdd.ts";
import {Role} from "../src/role.ts";

describe('Role', () => {
test('any', () => assertEquals(Role.any(), 'any'));
test('user without status', () => assertEquals(Role.user('custom'), 'user:custom'));
test('user with status', () => assertEquals(Role.user('custom', 'verified'), 'user:custom/verified'));
test('users without status', () => assertEquals(Role.users(), 'users'));
test('users with status', () => assertEquals(Role.users('verified'), 'users/verified'));
test('guests', () => assertEquals(Role.guests(), 'guests'));
test('team without role', () => assertEquals(Role.team('custom'), 'team:custom'))
test('team with role', () => assertEquals(Role.team('custom', 'owner'), 'team:custom/owner'))
test('member', () => assertEquals(Role.member('custom'), 'member:custom'))
test('label', () => assertEquals(Role.label('admin'), 'label:admin'))
})
Loading

0 comments on commit 2e3d7b7

Please sign in to comment.