Skip to content

Commit

Permalink
update: update test generator's data source.
Browse files Browse the repository at this point in the history
Signed-off-by: Jay <[email protected]>
  • Loading branch information
35C4n0r committed Nov 4, 2023
1 parent 3f3afb0 commit 33fe9cf
Show file tree
Hide file tree
Showing 25 changed files with 48 additions and 187 deletions.
141 changes: 1 addition & 140 deletions src/SDK/SDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,144 +69,6 @@ class SDK
'examples' => '',
'test' => 'false'
];
private array $errorTypes = [
'GeneralMock' => 'general_mock',
'GeneralArgumentInvalid' => 'general_argument_invalid',
'GeneralQueryLimitExceeded' => 'general_query_limit_exceeded',
'GeneralQueryInvalid' => 'general_query_invalid',
'GeneralCursorNotFound' => 'general_cursor_not_found',
'UserPasswordMismatch' => 'user_password_mismatch',
'PasswordRecentlyUsed' => 'password_recently_used',
'PasswordPersonalData' => 'password_personal_data',
'UserPhoneNotFound' => 'user_phone_not_found',
'UserMissingId' => 'user_missing_id',
'UserOauth2BadRequest' => 'user_oauth2_bad_request',
'StorageDeviceNotFound' => 'storage_device_not_found',
'StorageFileEmpty' => 'storage_file_empty',
'StorageFileTypeUnsupported' => 'storage_file_type_unsupported',
'StorageInvalidFileSize' => 'storage_invalid_file_size',
'StorageInvalidContentRange' => 'storage_invalid_content_range',
'StorageInvalidAppwriteId' => 'storage_invalid_appwrite_id',
'GeneralProviderFailure' => 'general_provider_failure',
'BuildNotReady' => 'build_not_ready',
'BuildInProgress' => 'build_in_progress',
'CollectionLimitExceeded' => 'collection_limit_exceeded',
'DocumentInvalidStructure' => 'document_invalid_structure',
'DocumentMissingData' => 'document_missing_data',
'DocumentMissingPayload' => 'document_missing_payload',
'AttributeUnknown' => 'attribute_unknown',
'AttributeNotAvailable' => 'attribute_not_available',
'AttributeFormatUnsupported' => 'attribute_format_unsupported',
'AttributeDefaultUnsupported' => 'attribute_default_unsupported',
'AttributeLimitExceeded' => 'attribute_limit_exceeded',
'AttributeValueInvalid' => 'attribute_value_invalid',
'AttributeTypeInvalid' => 'attribute_type_invalid',
'IndexLimitExceeded' => 'index_limit_exceeded',
'IndexInvalid' => 'index_invalid',
'ProjectUnknown' => 'project_unknown',
'ProjectInvalidSuccessUrl' => 'project_invalid_success_url',
'ProjectInvalidFailureUrl' => 'project_invalid_failure_url',
'ProjectReservedProject' => 'project_reserved_project',
'ProjectSmtpConfigInvalid' => 'project_smtp_config_invalid',
'GraphqlNoQuery' => 'graphql_no_query',
'GraphqlTooManyQueries' => 'graphql_too_many_queries',
'GeneralAccessForbidden' => 'general_access_forbidden',
'GeneralUnauthorizedScope' => 'general_unauthorized_scope',
'UserJwtInvalid' => 'user_jwt_invalid',
'UserBlocked' => 'user_blocked',
'UserInvalidToken' => 'user_invalid_token',
'UserEmailNotWhitelisted' => 'user_email_not_whitelisted',
'UserInvalidCode' => 'user_invalid_code',
'UserIpNotWhitelisted' => 'user_ip_not_whitelisted',
'UserInvalidCredentials' => 'user_invalid_credentials',
'UserAnonymousConsoleProhibited' => 'user_anonymous_console_prohibited',
'UserSessionAlreadyExists' => 'user_session_already_exists',
'UserUnauthorized' => 'user_unauthorized',
'UserOauth2Unauthorized' => 'user_oauth2_unauthorized',
'TeamInvalidSecret' => 'team_invalid_secret',
'TeamInviteMismatch' => 'team_invite_mismatch',
'ProjectKeyExpired' => 'project_key_expired',
'RuleVerificationFailed' => 'rule_verification_failed',
'ProjectTemplateDefaultDeletion' => 'project_template_default_deletion',
'GeneralUnknownOrigin' => 'general_unknown_origin',
'StorageInvalidFile' => 'storage_invalid_file',
'DocumentDeleteRestricted' => 'document_delete_restricted',
'GeneralRouteNotFound' => 'general_route_not_found',
'UserNotFound' => 'user_not_found',
'UserSessionNotFound' => 'user_session_not_found',
'UserIdentityNotFound' => 'user_identity_not_found',
'TeamNotFound' => 'team_not_found',
'TeamInviteNotFound' => 'team_invite_not_found',
'TeamMembershipMismatch' => 'team_membership_mismatch',
'MembershipNotFound' => 'membership_not_found',
'AvatarSetNotFound' => 'avatar_set_not_found',
'AvatarNotFound' => 'avatar_not_found',
'AvatarImageNotFound' => 'avatar_image_not_found',
'AvatarRemoteUrlFailed' => 'avatar_remote_url_failed',
'AvatarIconNotFound' => 'avatar_icon_not_found',
'StorageFileNotFound' => 'storage_file_not_found',
'StorageBucketNotFound' => 'storage_bucket_not_found',
'InstallationNotFound' => 'installation_not_found',
'ProviderRepositoryNotFound' => 'provider_repository_not_found',
'RepositoryNotFound' => 'repository_not_found',
'FunctionNotFound' => 'function_not_found',
'FunctionRuntimeUnsupported' => 'function_runtime_unsupported',
'BuildNotFound' => 'build_not_found',
'DeploymentNotFound' => 'deployment_not_found',
'ExecutionNotFound' => 'execution_not_found',
'DatabaseNotFound' => 'database_not_found',
'CollectionNotFound' => 'collection_not_found',
'DocumentNotFound' => 'document_not_found',
'AttributeNotFound' => 'attribute_not_found',
'IndexNotFound' => 'index_not_found',
'ProjectNotFound' => 'project_not_found',
'RouterHostNotFound' => 'router_host_not_found',
'RuleResourceNotFound' => 'rule_resource_not_found',
'RuleNotFound' => 'rule_not_found',
'WebhookNotFound' => 'webhook_not_found',
'KeyNotFound' => 'key_not_found',
'PlatformNotFound' => 'platform_not_found',
'VariableNotFound' => 'variable_not_found',
'MigrationNotFound' => 'migration_not_found',
'GeneralNotImplemented' => 'general_not_implemented',
'UserAlreadyExists' => 'user_already_exists',
'UserEmailAlreadyExists' => 'user_email_already_exists',
'UserPhoneAlreadyExists' => 'user_phone_already_exists',
'TeamInviteAlreadyExists' => 'team_invite_already_exists',
'TeamAlreadyExists' => 'team_already_exists',
'MembershipAlreadyConfirmed' => 'membership_already_confirmed',
'StorageFileAlreadyExists' => 'storage_file_already_exists',
'StorageBucketAlreadyExists' => 'storage_bucket_already_exists',
'ProviderContributionConflict' => 'provider_contribution_conflict',
'DatabaseAlreadyExists' => 'database_already_exists',
'CollectionAlreadyExists' => 'collection_already_exists',
'DocumentAlreadyExists' => 'document_already_exists',
'DocumentUpdateConflict' => 'document_update_conflict',
'AttributeAlreadyExists' => 'attribute_already_exists',
'IndexAlreadyExists' => 'index_already_exists',
'ProjectAlreadyExists' => 'project_already_exists',
'RuleAlreadyExists' => 'rule_already_exists',
'VariableAlreadyExists' => 'variable_already_exists',
'MigrationAlreadyExists' => 'migration_already_exists',
'MigrationInProgress' => 'migration_in_progress',
'UserPasswordResetRequired' => 'user_password_reset_required',
'ProjectProviderDisabled' => 'project_provider_disabled',
'StorageInvalidRange' => 'storage_invalid_range',
'UserOAuth2ProviderError' => 'user_oauth2_provider_error',
'GeneralRateLimitExceeded' => 'general_rate_limit_exceeded',
'GeneralUnknown' => 'general_unknown',
'GeneralServerError' => 'general_server_error',
'GeneralProtocolUnsupported' => 'general_protocol_unsupported',
'GeneralCodesDisabled' => 'general_codes_disabled',
'RouterDomainNotConfigured' => 'router_domain_not_configured',
'GeneralUsageDisabled' => 'general_usage_disabled',
'UserCountExceeded' => 'user_count_exceeded',
'UserAuthMethodUnsupported' => 'user_auth_method_unsupported',
'ProjectProviderUnsupported' => 'project_provider_unsupported',
'GeneralServiceDisabled' => 'general_service_disabled',
'GeneralSMTPDisabled' => 'general_smtp_disabled',
'GeneralPhoneDisabled' => 'general_phone_disabled'
];

/**
* SDK constructor.
Expand Down Expand Up @@ -693,8 +555,7 @@ public function generate(string $target): void
'name' => $this->language->getName(),
'params' => $this->language->getParams(),
],
'sdk' => $this->getParams(),
'testData' => ['enumData' => $this->errorTypes]
'sdk' => $this->getParams()
];

foreach ($this->language->getFiles() as $file) {
Expand Down
4 changes: 2 additions & 2 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function getDefinitions()
"name" => $key,
"properties" => $schema['properties'] ?? [],
"description" => $schema['description'] ?? [],
"error_types" => $schema['x-appwrite']['types'] ?? null,
"errorTypes" => $schema['x-appwrite']['types'] ?? null,
"required" => $schema['required'] ?? [],
"additionalProperties" => $schema['additionalProperties'] ?? []
];
Expand Down Expand Up @@ -345,7 +345,7 @@ public function getDefinitions()
$types[] = [
'code' => $type['code'],
'type' => $type['type'],
'description' => $type['description']
'message' => $type['message']
];
}
$sch['errorTypes'] = $types;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class {{spec.title | caseUcfirst}} Exception(
) : Exception(message)

enum class ErrorType(val value: String) {
{% for error in spec.definitions.appwriteException.error_types %}
{% for error in spec.definitions.appwriteException.errorTypes %}
/**
* {{ error.description }}
* {{ error.message }}
*/
{{ error.type|title|replace({'_': ''}) }}("{{ error.type }}"),
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions templates/android/tests/TestException.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class TestException {

@Test
fun testEnumValues() {
{% for key, value in testData.enumData %}
assertEquals(ErrorType.{{ key }}.value), "{{ value }}")
{% for error in spec.definitions.appwriteException.errorTypes %}
assertEquals(ErrorType.{{ error.type|title|replace({'_': ''}) }}.value), "{{ error.type }}")
{% endfor %}
}
}
4 changes: 2 additions & 2 deletions templates/dart/lib/src/exception.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class {{spec.title | caseUcfirst}}Exception implements Exception {
}

enum ErrorType {
{% for error in spec.definitions.appwriteException.error_types %}
/// {{ error.description }}
{% for error in spec.definitions.appwriteException.errorTypes %}
/// {{ error.message }}
{{ error.type|title|replace({'_': ''}) }},
{% endfor %}
}
2 changes: 1 addition & 1 deletion templates/dart/test/src/exception_test.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void main() {
group('ErrorType Enum Test', () {
{% for key, value in testData.enumData %}
test('ErrorType.{{ key }} should have correct value', () {
expect(ErrorType.{{ key }}.toString(), equals('ErrorType.{{ value }}'));
expect(ErrorType.{{ error.type|title|replace({'_': ''}) }}.toString(), equals('ErrorType.{{ error.type }}'));
});
{% endfor %}
});
Expand Down
4 changes: 2 additions & 2 deletions templates/deno/src/exception.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class {{ spec.title | caseUcfirst}}Exception {
}

export enum ErrorType {
{% for error in spec.definitions.appwriteException.error_types %}
{% for error in spec.definitions.appwriteException.errorTypes %}
/**
* {{ error.description }}
* {{ error.message }}
*/
{{ error.type|title|replace({'_': ''}) }} = "{{ error.type }}",
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions templates/deno/tests/test_exception.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {assertEquals} from "https://deno.land/std/testing/asserts.ts";
import {ErrorType} from "../src/exception.ts";

Deno.test("ErrorType values should match expected strings", () => {
{% for key, value in testData.enumData %}
assertEquals(ErrorType.{{ key }}, '{{ value }}');
{% for error in spec.definitions.appwriteException.errorTypes %}
assertEquals(ErrorType.{{ error.type|title|replace({'_': ''}) }}, '{{ error.type }}');
{% endfor %}
})
4 changes: 2 additions & 2 deletions templates/dotnet/src/Appwrite/Exception.cs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace {{spec.title | caseUcfirst}}
}

public enum ErrorType {
{% for error in spec.definitions.appwriteException.error_types %}
{% for error in spec.definitions.appwriteException.errorTypes %}
/// <summary>
/// {{ error.description }}
/// {{ error.message }}
/// </summary>
{{ error.type|title|replace({'_': ''}) }},
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions templates/dotnet/tests/TestException.cs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class TestException
[TestMethod]
public void TestEnumValues()
{
{% for key, value in testData.enumData %}
Assert.AreEqual(ErrorType.{{ key }}, "{{ value }}");
{% for error in spec.definitions.appwriteException.errorTypes %}
Assert.AreEqual(ErrorType.{{ error.type|title|replace({'_': ''}) }}, "{{ error.type }}");
{% endfor %}
}
}
4 changes: 2 additions & 2 deletions templates/flutter/lib/src/exception.dart.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enum ErrorType {
{% for error in spec.definitions.appwriteException.error_types %}
/// {{ error.description }}
{% for error in spec.definitions.appwriteException.errorTypes %}
/// {{ error.message }}
{{ error.type|title|replace({'_': ''}) }},
{% endfor %}
}
4 changes: 2 additions & 2 deletions templates/flutter/test/src/exception_test.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import 'package:flutter_test/flutter_test.dart';

void main() {
group('ErrorType Enum Test', () {
{% for key, value in testData.enumData %}
{% for error in spec.definitions.appwriteException.errorTypes %}
test('ErrorType.{{ key }} should have correct value', () {
expect(ErrorType.{{ key }}.toString(), equals('ErrorType.{{ value }}'));
expect(ErrorType.{{ error.type|title|replace({'_': ''}) }}.toString(), equals('ErrorType.{{ error.type }}'));
});
{% endfor %}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class {{spec.title | caseUcfirst}}Exception(
) : Exception(message)

enum class ErrorType(val value: String) {
{% for error in spec.definitions.appwriteException.error_types %}
{% for error in spec.definitions.appwriteException.errorTypes %}
/**
* {{ error.description }}
* {{ error.message }}
*/
{{ error.type|title|replace({'_': ''}) }}("{{ error.type }}"),
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions templates/kotlin/tests/TestException.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class TestException {

@Test
fun testEnumValues() {
{% for key, value in testData.enumData %}
assertEquals(ErrorType.{{ key }}.value), "{{ value }}")
{% for error in spec.definitions.appwriteException.errorTypes %}
assertEquals(ErrorType.{{ error.type|title|replace({'_': ''}) }}.value), "{{ error.type }}")
{% endfor %}
}
}
4 changes: 2 additions & 2 deletions templates/node/lib/exception.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class {{spec.title | caseUcfirst}}Exception extends Error {
module.exports = {{spec.title | caseUcfirst}}Exception;

const ErrorType = {
{% for error in spec.definitions.appwriteException.error_types %}
{% for error in spec.definitions.appwriteException.errorTypes %}
/**
* {{ error.description }}
* {{ error.message }}
*/
{{ error.type|title|replace({'_': ''}) }}: "{{ error.type }}",
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions templates/node/tests/test_exception.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const assert = require('assert');
const ErrorType = require('../lib/exception.js');

try {
{% for key, value in testData.enumData %}
assert.strictEqual(ErrorType.{{ key }}, '{{ value }}');
{% for error in spec.definitions.appwriteException.errorTypes %}
assert.strictEqual(ErrorType.{{ error.type|title|replace({'_': ''}) }}, '{{ error.type }}');
{% endfor %}

console.log('All tests passed!');
Expand Down
4 changes: 2 additions & 2 deletions templates/php/src/Exception.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class {{spec.title | caseUcfirst}}Exception extends Exception {
}
class ErrorType {
{% for error in spec.definitions.appwriteException.error_types %}
{% for error in spec.definitions.appwriteException.errorTypes %}
/**
* {{ error.description }}
* {{ error.message }}
*/
const {{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}';
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions templates/php/tests/TestException.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use PHPUnit\Framework\TestCase;
class TestErrorEnum extends TestCase {

public function testEnumValues() {
{% for key, value in testData.enumData %}
$this->assertEquals(ErrorType::{{ key }}, '{{ value }}');
{% for error in spec.definitions.appwriteException.errorTypes %}
$this->assertEquals(ErrorType::{{ error.type|title|replace({'_': ''}) }}, '{{ error.type }}');
{% endfor %}
}
}
4 changes: 2 additions & 2 deletions templates/python/package/exception.py.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class {{spec.title | caseUcfirst}}Exception(Exception):


class ErrorType(Enum):
{% for error in spec.definitions.appwriteException.error_types %}
{% for error in spec.definitions.appwriteException.errorTypes %}
"""
{{ error.description }}
{{ error.message }}
"""
{{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}'
{% endfor %}
4 changes: 2 additions & 2 deletions templates/ruby/lib/container/exception.rb.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module {{spec.title | caseUcfirst}}
end

class ErrorType
{% for error in spec.definitions.appwriteException.error_types %}
# {{ error.description }}
{% for error in spec.definitions.appwriteException.errorTypes %}
# {{ error.message }}
{{ error.type|title|replace({'_': ''}) }} = '{{ error.type }}'
{% endfor %}
end
4 changes: 2 additions & 2 deletions templates/ruby/tests/lib/appwrite/test_exception.rb.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ require_relative '../../../lib/{{ spec.title | caseSnake }}/exception' # Ensure
class ErrorTypeTest < Test::Unit::TestCase

def test_error_type_values
{% for key, value in testData.enumData %}
assert_equal('{{ value }}', ErrorType::{{ key }})
{% for error in spec.definitions.appwriteException.errorTypes %}
assert_equal('{{ error.type }}', ErrorType::{{ error.type|title|replace({'_': ''}) }})
{% endfor %}
end
end
4 changes: 2 additions & 2 deletions templates/swift/Sources/Exception.swift.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enum ErrorType: String {
{% for error in spec.definitions.appwriteException.error_types %}
/// {{ error.description }}
{% for error in spec.definitions.appwriteException.errorTypes %}
/// {{ error.message }}
case {{ error.type|camelCase }} = "{{ error.type }}"
{% endfor %}
}
Loading

0 comments on commit 33fe9cf

Please sign in to comment.