Skip to content

Commit

Permalink
Fix: Support named and optional args in test tools (serverpod#2784)
Browse files Browse the repository at this point in the history
  • Loading branch information
hampuslavin authored Sep 30, 2024
1 parent a6ec360 commit 387ff78
Show file tree
Hide file tree
Showing 11 changed files with 1,595 additions and 193 deletions.
115 changes: 115 additions & 0 deletions tests/serverpod_test_client/lib/src/protocol/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,117 @@ class EndpointMapParameters extends _i1.EndpointRef {
);
}

/// {@category Endpoint}
class EndpointMethodSignaturePermutations extends _i1.EndpointRef {
EndpointMethodSignaturePermutations(_i1.EndpointCaller caller)
: super(caller);

@override
String get name => 'methodSignaturePermutations';

_i2.Future<String> echoPositionalArg(String string) =>
caller.callServerEndpoint<String>(
'methodSignaturePermutations',
'echoPositionalArg',
{'string': string},
);

_i2.Future<String> echoNamedArg({required String string}) =>
caller.callServerEndpoint<String>(
'methodSignaturePermutations',
'echoNamedArg',
{'string': string},
);

_i2.Future<String?> echoNullableNamedArg({String? string}) =>
caller.callServerEndpoint<String?>(
'methodSignaturePermutations',
'echoNullableNamedArg',
{'string': string},
);

_i2.Future<String?> echoOptionalArg([String? string]) =>
caller.callServerEndpoint<String?>(
'methodSignaturePermutations',
'echoOptionalArg',
{'string': string},
);

_i2.Future<List<String?>> echoPositionalAndNamedArgs(
String string1, {
required String string2,
}) =>
caller.callServerEndpoint<List<String?>>(
'methodSignaturePermutations',
'echoPositionalAndNamedArgs',
{
'string1': string1,
'string2': string2,
},
);

_i2.Future<List<String?>> echoPositionalAndNullableNamedArgs(
String string1, {
String? string2,
}) =>
caller.callServerEndpoint<List<String?>>(
'methodSignaturePermutations',
'echoPositionalAndNullableNamedArgs',
{
'string1': string1,
'string2': string2,
},
);

_i2.Future<List<String?>> echoPositionalAndOptionalArgs(
String string1, [
String? string2,
]) =>
caller.callServerEndpoint<List<String?>>(
'methodSignaturePermutations',
'echoPositionalAndOptionalArgs',
{
'string1': string1,
'string2': string2,
},
);

_i2.Stream<String> echoNamedArgStream(
{required _i2.Stream<String> strings}) =>
caller.callStreamingServerEndpoint<_i2.Stream<String>, String>(
'methodSignaturePermutations',
'echoNamedArgStream',
{},
{'strings': strings},
);

_i2.Future<String> echoNamedArgStreamAsFuture(
{required _i2.Stream<String> strings}) =>
caller.callStreamingServerEndpoint<_i2.Future<String>, String>(
'methodSignaturePermutations',
'echoNamedArgStreamAsFuture',
{},
{'strings': strings},
);

_i2.Stream<String> echoPositionalArgStream(_i2.Stream<String> strings) =>
caller.callStreamingServerEndpoint<_i2.Stream<String>, String>(
'methodSignaturePermutations',
'echoPositionalArgStream',
{},
{'strings': strings},
);

_i2.Future<String> echoPositionalArgStreamAsFuture(
_i2.Stream<String> strings) =>
caller.callStreamingServerEndpoint<_i2.Future<String>, String>(
'methodSignaturePermutations',
'echoPositionalArgStreamAsFuture',
{},
{'strings': strings},
);
}

/// {@category Endpoint}
class EndpointMethodStreaming extends _i1.EndpointRef {
EndpointMethodStreaming(_i1.EndpointCaller caller) : super(caller);
Expand Down Expand Up @@ -2199,6 +2310,7 @@ class Client extends _i1.ServerpodClientShared {
streamQueryLogging = EndpointStreamQueryLogging(this);
loggingDisabled = EndpointLoggingDisabled(this);
mapParameters = EndpointMapParameters(this);
methodSignaturePermutations = EndpointMethodSignaturePermutations(this);
methodStreaming = EndpointMethodStreaming(this);
authenticatedMethodStreaming = EndpointAuthenticatedMethodStreaming(this);
moduleSerialization = EndpointModuleSerialization(this);
Expand Down Expand Up @@ -2262,6 +2374,8 @@ class Client extends _i1.ServerpodClientShared {

late final EndpointMapParameters mapParameters;

late final EndpointMethodSignaturePermutations methodSignaturePermutations;

late final EndpointMethodStreaming methodStreaming;

late final EndpointAuthenticatedMethodStreaming authenticatedMethodStreaming;
Expand Down Expand Up @@ -2320,6 +2434,7 @@ class Client extends _i1.ServerpodClientShared {
'streamQueryLogging': streamQueryLogging,
'loggingDisabled': loggingDisabled,
'mapParameters': mapParameters,
'methodSignaturePermutations': methodSignaturePermutations,
'methodStreaming': methodStreaming,
'authenticatedMethodStreaming': authenticatedMethodStreaming,
'moduleSerialization': moduleSerialization,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import 'package:serverpod/serverpod.dart';

class MethodSignaturePermutationsEndpoint extends Endpoint {
Future<String> echoPositionalArg(
Session session,
String string,
) async {
return string;
}

Future<String> echoNamedArg(
Session session, {
required String string,
}) async {
return string;
}

Future<String?> echoNullableNamedArg(
Session session, {
String? string,
}) async {
return string;
}

Future<String?> echoOptionalArg(
Session session, [
String? string,
]) async {
return string;
}

Future<List<String?>> echoPositionalAndNamedArgs(
Session session,
String string1, {
required String string2,
}) async {
return [string1, string2];
}

Future<List<String?>> echoPositionalAndNullableNamedArgs(
Session session,
String string1, {
String? string2,
}) async {
return [string1, string2];
}

Future<List<String?>> echoPositionalAndOptionalArgs(
Session session, String string1,
[String? string2]) async {
return [string1, string2];
}

Stream<String> echoNamedArgStream(
Session session, {
required Stream<String> strings,
}) async* {
await for (var string in strings) {
yield string;
}
}

Future<String> echoNamedArgStreamAsFuture(
Session session, {
required Stream<String> strings,
}) async {
return strings.first;
}

Stream<String> echoPositionalArgStream(
Session session, Stream<String> strings) async* {
await for (var string in strings) {
yield string;
}
}

Future<String> echoPositionalArgStreamAsFuture(
Session session, Stream<String> strings) async {
return strings.first;
}
}
Loading

0 comments on commit 387ff78

Please sign in to comment.