mirror of
https://github.com/appwrite/sdk-for-dart.git
synced 2026-11-18 20:47:29 +00:00
113 lines
3.0 KiB
Dart
113 lines
3.0 KiB
Dart
import 'package:test/test.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
import 'package:dart_appwrite/models.dart' as models;
|
|
import 'package:dart_appwrite/enums.dart' as enums;
|
|
import 'package:dart_appwrite/src/enums.dart';
|
|
import 'package:dart_appwrite/src/response.dart';
|
|
import 'dart:typed_data';
|
|
import 'package:dart_appwrite/dart_appwrite.dart';
|
|
|
|
class MockClient extends Mock implements Client {
|
|
Map<String, String> config = {'project': 'testproject'};
|
|
String endPoint = 'https://localhost/v1';
|
|
|
|
@override
|
|
Future<Response> call(
|
|
HttpMethod? method, {
|
|
String? path = '',
|
|
Map<String, String>? headers = const {},
|
|
Map<String, dynamic>? params = const {},
|
|
ResponseType? responseType,
|
|
}) async {
|
|
return super.noSuchMethod(
|
|
Invocation.method(#call, [method], {
|
|
#path: path,
|
|
#headers: headers,
|
|
#params: params,
|
|
#responseType: responseType,
|
|
}),
|
|
returnValue: Response(),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<String?> webAuth(Uri? url) async {
|
|
return super.noSuchMethod(
|
|
Invocation.method(#webAuth, [url]),
|
|
returnValue: 'done',
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<Response> chunkedUpload({
|
|
String? path,
|
|
Map<String, dynamic>? params,
|
|
String? paramName,
|
|
String? idParamName,
|
|
Map<String, String>? headers,
|
|
Function(UploadProgress)? onProgress,
|
|
ResponseType? responseType,
|
|
HttpMethod? method = HttpMethod.post,
|
|
}) async {
|
|
return super.noSuchMethod(
|
|
Invocation.method(#chunkedUpload, [], {
|
|
#path: path,
|
|
#params: params,
|
|
#paramName: paramName,
|
|
#idParamName: idParamName,
|
|
#headers: headers,
|
|
#method: method,
|
|
}),
|
|
returnValue: Response(data: {}),
|
|
);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
group('Embeddings test', () {
|
|
late MockClient client;
|
|
late Embeddings embeddings;
|
|
|
|
setUp(() {
|
|
client = MockClient();
|
|
embeddings = Embeddings(client);
|
|
});
|
|
|
|
test('test method createTextEmbeddings()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'embeddings': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await embeddings.createTextEmbeddings(
|
|
texts: [],
|
|
model: enums.EmbeddingModel.nomicEmbedText,
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: "/embeddings/text",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"texts": isA<List>(),
|
|
"model": enums.EmbeddingModel.nomicEmbedText.value,
|
|
});
|
|
expect(response, isA<models.EmbeddingList>());
|
|
});
|
|
});
|
|
}
|