mirror of
https://github.com/appwrite/sdk-for-dart.git
synced 2026-11-18 20:47:29 +00:00
1663 lines
51 KiB
Dart
1663 lines
51 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('DocumentsDB test', () {
|
|
late MockClient client;
|
|
late DocumentsDB documentsDB;
|
|
|
|
setUp(() {
|
|
client = MockClient();
|
|
documentsDB = DocumentsDB(client);
|
|
});
|
|
|
|
test('test method list()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'databases': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.list(
|
|
queries: [],
|
|
total: false,
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"queries": isA<List>(),
|
|
"total": false,
|
|
});
|
|
expect(response, isA<models.DatabaseList>());
|
|
});
|
|
|
|
test('test method create()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'name': "My Database",
|
|
'description': "Customer orders and invoices.",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'enabled': true,
|
|
'type': "legacy",
|
|
};
|
|
|
|
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 documentsDB.create(
|
|
databaseId: "<DATABASE_ID>",
|
|
name: "<NAME>",
|
|
enabled: false,
|
|
description: "<DESCRIPTION>",
|
|
specification: "serverless",
|
|
replicas: 1,
|
|
syncMode: "async",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: "/documentsdb",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"databaseId": "<DATABASE_ID>",
|
|
"name": "<NAME>",
|
|
"enabled": false,
|
|
"description": "<DESCRIPTION>",
|
|
"specification": "serverless",
|
|
"replicas": 1,
|
|
"syncMode": "async",
|
|
});
|
|
expect(response, isA<models.Database>());
|
|
});
|
|
|
|
test('test method listSpecifications()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'specifications': [],
|
|
'total': 9,
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.listSpecifications();
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/specifications",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
expect(response, isA<models.DedicatedDatabaseSpecificationList>());
|
|
});
|
|
|
|
test('test method listTransactions()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'transactions': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.listTransactions(
|
|
queries: [],
|
|
total: false,
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/transactions",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"queries": isA<List>(),
|
|
"total": false,
|
|
});
|
|
expect(response, isA<models.TransactionList>());
|
|
});
|
|
|
|
test('test method createTransaction()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "259125845563242502",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'status': "pending",
|
|
'operations': 5,
|
|
'expiresAt': "2020-10-15T06:38:00.000+00:00",
|
|
};
|
|
|
|
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 documentsDB.createTransaction(
|
|
ttl: 1,
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: "/documentsdb/transactions",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"ttl": 1,
|
|
});
|
|
expect(response, isA<models.Transaction>());
|
|
});
|
|
|
|
test('test method getTransaction()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "259125845563242502",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'status': "pending",
|
|
'operations': 5,
|
|
'expiresAt': "2020-10-15T06:38:00.000+00:00",
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.getTransaction(
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/transactions/%3CTRANSACTION_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
expect(response, isA<models.Transaction>());
|
|
});
|
|
|
|
test('test method updateTransaction()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "259125845563242502",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'status': "pending",
|
|
'operations': 5,
|
|
'expiresAt': "2020-10-15T06:38:00.000+00:00",
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.patch,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.updateTransaction(
|
|
transactionId: "<TRANSACTION_ID>",
|
|
commit: false,
|
|
rollback: false,
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.patch,
|
|
path: "/documentsdb/transactions/%3CTRANSACTION_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"commit": false,
|
|
"rollback": false,
|
|
});
|
|
expect(response, isA<models.Transaction>());
|
|
});
|
|
|
|
test('test method deleteTransaction()', () async {
|
|
final data = '';
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.deleteTransaction(
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: "/documentsdb/transactions/%3CTRANSACTION_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
});
|
|
|
|
test('test method createOperations()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "259125845563242502",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'status': "pending",
|
|
'operations': 5,
|
|
'expiresAt': "2020-10-15T06:38:00.000+00:00",
|
|
};
|
|
|
|
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 documentsDB.createOperations(
|
|
transactionId: "<TRANSACTION_ID>",
|
|
operations: [],
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: "/documentsdb/transactions/%3CTRANSACTION_ID%3E/operations",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"operations": isA<List>(),
|
|
});
|
|
expect(response, isA<models.Transaction>());
|
|
});
|
|
|
|
test('test method get()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'name': "My Database",
|
|
'description': "Customer orders and invoices.",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'enabled': true,
|
|
'type': "legacy",
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.get(
|
|
databaseId: "<DATABASE_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
expect(response, isA<models.Database>());
|
|
});
|
|
|
|
test('test method update()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'name': "My Database",
|
|
'description': "Customer orders and invoices.",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'enabled': true,
|
|
'type': "legacy",
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.put,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.update(
|
|
databaseId: "<DATABASE_ID>",
|
|
name: "<NAME>",
|
|
enabled: false,
|
|
description: "<DESCRIPTION>",
|
|
specification: "serverless",
|
|
replicas: 1,
|
|
syncMode: "async",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.put,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"name": "<NAME>",
|
|
"enabled": false,
|
|
"description": "<DESCRIPTION>",
|
|
"specification": "serverless",
|
|
"replicas": 1,
|
|
"syncMode": "async",
|
|
});
|
|
expect(response, isA<models.Database>());
|
|
});
|
|
|
|
test('test method delete()', () async {
|
|
final data = '';
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.delete(
|
|
databaseId: "<DATABASE_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
});
|
|
|
|
test('test method listCollections()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'collections': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.listCollections(
|
|
databaseId: "<DATABASE_ID>",
|
|
queries: [],
|
|
search: "<SEARCH>",
|
|
total: false,
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"queries": isA<List>(),
|
|
"search": "<SEARCH>",
|
|
"total": false,
|
|
});
|
|
expect(response, isA<models.CollectionList>());
|
|
});
|
|
|
|
test('test method createCollection()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$permissions': [],
|
|
'databaseId': "5e5ea5c16897e",
|
|
'name': "My Collection",
|
|
'description': "Movies available in the catalog.",
|
|
'enabled': true,
|
|
'documentSecurity': true,
|
|
'attributes': [],
|
|
'indexes': [],
|
|
'bytesMax': 65535,
|
|
'bytesUsed': 1500,
|
|
};
|
|
|
|
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 documentsDB.createCollection(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
name: "<NAME>",
|
|
permissions: [],
|
|
documentSecurity: false,
|
|
enabled: false,
|
|
attributes: [],
|
|
indexes: [],
|
|
description: "<DESCRIPTION>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"collectionId": "<COLLECTION_ID>",
|
|
"name": "<NAME>",
|
|
"permissions": isA<List>(),
|
|
"documentSecurity": false,
|
|
"enabled": false,
|
|
"attributes": isA<List>(),
|
|
"indexes": isA<List>(),
|
|
"description": "<DESCRIPTION>",
|
|
});
|
|
expect(response, isA<models.Collection>());
|
|
});
|
|
|
|
test('test method getCollection()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$permissions': [],
|
|
'databaseId': "5e5ea5c16897e",
|
|
'name': "My Collection",
|
|
'description': "Movies available in the catalog.",
|
|
'enabled': true,
|
|
'documentSecurity': true,
|
|
'attributes': [],
|
|
'indexes': [],
|
|
'bytesMax': 65535,
|
|
'bytesUsed': 1500,
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.getCollection(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
expect(response, isA<models.Collection>());
|
|
});
|
|
|
|
test('test method updateCollection()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$permissions': [],
|
|
'databaseId': "5e5ea5c16897e",
|
|
'name': "My Collection",
|
|
'description': "Movies available in the catalog.",
|
|
'enabled': true,
|
|
'documentSecurity': true,
|
|
'attributes': [],
|
|
'indexes': [],
|
|
'bytesMax': 65535,
|
|
'bytesUsed': 1500,
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.put,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.updateCollection(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
name: "<NAME>",
|
|
permissions: [],
|
|
documentSecurity: false,
|
|
enabled: false,
|
|
purge: false,
|
|
description: "<DESCRIPTION>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.put,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"name": "<NAME>",
|
|
"permissions": isA<List>(),
|
|
"documentSecurity": false,
|
|
"enabled": false,
|
|
"purge": false,
|
|
"description": "<DESCRIPTION>",
|
|
});
|
|
expect(response, isA<models.Collection>());
|
|
});
|
|
|
|
test('test method deleteCollection()', () async {
|
|
final data = '';
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.deleteCollection(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
});
|
|
|
|
test('test method listDocuments()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'documents': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.listDocuments(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
queries: [],
|
|
transactionId: "<TRANSACTION_ID>",
|
|
total: false,
|
|
ttl: 1,
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"queries": isA<List>(),
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
"total": false,
|
|
"ttl": 1,
|
|
});
|
|
expect(response, isA<models.DocumentList>());
|
|
});
|
|
|
|
test('test method createDocument()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$sequence': "1",
|
|
'\$collectionId': "5e5ea5c15117e",
|
|
'\$databaseId': "5e5ea5c15117e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$permissions': [],
|
|
};
|
|
|
|
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 documentsDB.createDocument(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
documentId: "<DOCUMENT_ID>",
|
|
data: {},
|
|
permissions: [],
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"documentId": "<DOCUMENT_ID>",
|
|
"data": isA<Map>(),
|
|
"permissions": isA<List>(),
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
expect(response, isA<models.Document>());
|
|
});
|
|
|
|
test('test method createDocuments()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'documents': [],
|
|
};
|
|
|
|
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 documentsDB.createDocuments(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
documents: [],
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"documents": isA<List>(),
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
expect(response, isA<models.DocumentList>());
|
|
});
|
|
|
|
test('test method upsertDocuments()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'documents': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.put,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.upsertDocuments(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
documents: [],
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.put,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"documents": isA<List>(),
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
expect(response, isA<models.DocumentList>());
|
|
});
|
|
|
|
test('test method updateDocuments()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'documents': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.patch,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.updateDocuments(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
data: {},
|
|
queries: [],
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.patch,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"data": isA<Map>(),
|
|
"queries": isA<List>(),
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
expect(response, isA<models.DocumentList>());
|
|
});
|
|
|
|
test('test method deleteDocuments()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'documents': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.deleteDocuments(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
queries: [],
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"queries": isA<List>(),
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
expect(response, isA<models.DocumentList>());
|
|
});
|
|
|
|
test('test method createQuery()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'documents': [],
|
|
};
|
|
|
|
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 documentsDB.createQuery(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
queries: [],
|
|
transactionId: "<TRANSACTION_ID>",
|
|
total: false,
|
|
ttl: 1,
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents/query",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"queries": isA<List>(),
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
"total": false,
|
|
"ttl": 1,
|
|
});
|
|
expect(response, isA<models.DocumentList>());
|
|
});
|
|
|
|
test('test method getDocument()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$sequence': "1",
|
|
'\$collectionId': "5e5ea5c15117e",
|
|
'\$databaseId': "5e5ea5c15117e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$permissions': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.getDocument(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
documentId: "<DOCUMENT_ID>",
|
|
queries: [],
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents/%3CDOCUMENT_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"queries": isA<List>(),
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
expect(response, isA<models.Document>());
|
|
});
|
|
|
|
test('test method upsertDocument()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$sequence': "1",
|
|
'\$collectionId': "5e5ea5c15117e",
|
|
'\$databaseId': "5e5ea5c15117e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$permissions': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.put,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.upsertDocument(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
documentId: "<DOCUMENT_ID>",
|
|
data: {},
|
|
permissions: [],
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.put,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents/%3CDOCUMENT_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"data": isA<Map>(),
|
|
"permissions": isA<List>(),
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
expect(response, isA<models.Document>());
|
|
});
|
|
|
|
test('test method updateDocument()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$sequence': "1",
|
|
'\$collectionId': "5e5ea5c15117e",
|
|
'\$databaseId': "5e5ea5c15117e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$permissions': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.patch,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.updateDocument(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
documentId: "<DOCUMENT_ID>",
|
|
data: {},
|
|
permissions: [],
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.patch,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents/%3CDOCUMENT_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"data": isA<Map>(),
|
|
"permissions": isA<List>(),
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
expect(response, isA<models.Document>());
|
|
});
|
|
|
|
test('test method deleteDocument()', () async {
|
|
final data = '';
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.deleteDocument(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
documentId: "<DOCUMENT_ID>",
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents/%3CDOCUMENT_ID%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
});
|
|
|
|
test('test method decrementDocumentAttribute()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$sequence': "1",
|
|
'\$collectionId': "5e5ea5c15117e",
|
|
'\$databaseId': "5e5ea5c15117e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$permissions': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.patch,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.decrementDocumentAttribute(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
documentId: "<DOCUMENT_ID>",
|
|
attribute: "<ATTRIBUTE>",
|
|
value: 1.0,
|
|
min: 1.0,
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.patch,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents/%3CDOCUMENT_ID%3E/%3CATTRIBUTE%3E/decrement",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"value": 1.0,
|
|
"min": 1.0,
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
expect(response, isA<models.Document>());
|
|
});
|
|
|
|
test('test method incrementDocumentAttribute()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$sequence': "1",
|
|
'\$collectionId': "5e5ea5c15117e",
|
|
'\$databaseId': "5e5ea5c15117e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$permissions': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.patch,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.incrementDocumentAttribute(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
documentId: "<DOCUMENT_ID>",
|
|
attribute: "<ATTRIBUTE>",
|
|
value: 1.0,
|
|
max: 1.0,
|
|
transactionId: "<TRANSACTION_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.patch,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/documents/%3CDOCUMENT_ID%3E/%3CATTRIBUTE%3E/increment",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"value": 1.0,
|
|
"max": 1.0,
|
|
"transactionId": "<TRANSACTION_ID>",
|
|
});
|
|
expect(response, isA<models.Document>());
|
|
});
|
|
|
|
test('test method listIndexes()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'indexes': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.listIndexes(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
queries: [],
|
|
total: false,
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/indexes",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"queries": isA<List>(),
|
|
"total": false,
|
|
});
|
|
expect(response, isA<models.IndexList>());
|
|
});
|
|
|
|
test('test method createIndex()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'key': "index1",
|
|
'description': "Speeds up lookups by email.",
|
|
'type': "primary",
|
|
'status': "available",
|
|
'error': "string",
|
|
'attributes': [],
|
|
'lengths': [],
|
|
};
|
|
|
|
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 documentsDB.createIndex(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
key: "<KEY>",
|
|
type: enums.DocumentsDBIndexType.key,
|
|
attributes: [],
|
|
orders: [enums.OrderBy.asc],
|
|
lengths: [],
|
|
description: "<DESCRIPTION>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/indexes",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"key": "<KEY>",
|
|
"type": enums.DocumentsDBIndexType.key.value,
|
|
"attributes": isA<List>(),
|
|
"orders": isA<List>(),
|
|
"lengths": isA<List>(),
|
|
"description": "<DESCRIPTION>",
|
|
});
|
|
expect(response, isA<models.Index>());
|
|
});
|
|
|
|
test('test method getIndex()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'key': "index1",
|
|
'description': "Speeds up lookups by email.",
|
|
'type': "primary",
|
|
'status': "available",
|
|
'error': "string",
|
|
'attributes': [],
|
|
'lengths': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.getIndex(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
key: "<KEY>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/indexes/%3CKEY%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
expect(response, isA<models.Index>());
|
|
});
|
|
|
|
test('test method deleteIndex()', () async {
|
|
final data = '';
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.deleteIndex(
|
|
databaseId: "<DATABASE_ID>",
|
|
collectionId: "<COLLECTION_ID>",
|
|
key: "<KEY>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.delete,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/collections/%3CCOLLECTION_ID%3E/indexes/%3CKEY%3E",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
});
|
|
|
|
test('test method createFailover()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'\$id': "5e5ea5c16897e",
|
|
'\$createdAt': "2020-10-15T06:38:00.000+00:00",
|
|
'\$updatedAt': "2020-10-15T06:38:00.000+00:00",
|
|
'projectId': "5e5ea5c16897e",
|
|
'name': "My Production Database",
|
|
'version': "16",
|
|
'specification': "s-2vcpu-2gb",
|
|
'backend': "edge",
|
|
'hostname': "db-myproject-mydb.fra.appwrite.center",
|
|
'connectionUser': "appwrite_user",
|
|
'connectionPassword': "••••••••",
|
|
'connectionString':
|
|
"postgresql://user:pass@db-myproject-mydb.fra.appwrite.center:5432/postgres?sslmode=require",
|
|
'ssl': true,
|
|
'status': "ready",
|
|
'containerStatus': "active",
|
|
'lifecycleState': "active",
|
|
'idleTimeoutMinutes': 15,
|
|
'cpu': 2000,
|
|
'memory': 4096,
|
|
'storage': 100,
|
|
'storageStatus': "resizing",
|
|
'storageTargetGb': 120,
|
|
'storageClass': "ssd",
|
|
'storageMaxGb': 100,
|
|
'nodePool': "db-pool-4vcpu-8gb",
|
|
'replicas': 2,
|
|
'syncMode': "async",
|
|
'networkMaxConnections': 500,
|
|
'networkIdleTimeoutSeconds': 900,
|
|
'networkIPAllowlist': [],
|
|
'backupEnabled': true,
|
|
'pitr': true,
|
|
'pitrRetentionDays': 14,
|
|
'storageAutoscaling': true,
|
|
'storageAutoscalingThresholdPercent': 85,
|
|
'storageAutoscalingMaxGb': 30,
|
|
'maintenanceWindowDay': "sun",
|
|
'maintenanceWindowHourUtc': 3,
|
|
'metricsEnabled': true,
|
|
'sqlApiEnabled': true,
|
|
'sqlApiAllowedStatements': [],
|
|
'sqlApiMaxRows': 10000,
|
|
'sqlApiMaxBytes': 10485760,
|
|
'sqlApiTimeoutSeconds': 30,
|
|
'error': "",
|
|
};
|
|
|
|
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 documentsDB.createFailover(
|
|
databaseId: "<DATABASE_ID>",
|
|
targetReplicaId: "<TARGET_REPLICA_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.post,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/failovers",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"targetReplicaId": "<TARGET_REPLICA_ID>",
|
|
});
|
|
expect(response, isA<models.DedicatedDatabase>());
|
|
});
|
|
|
|
test('test method listOperations()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'total': 5,
|
|
'operations': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.listOperations(
|
|
databaseId: "<DATABASE_ID>",
|
|
status: "queued",
|
|
limit: 1,
|
|
offset: 1,
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/operations",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, {
|
|
"status": "queued",
|
|
"limit": 1,
|
|
"offset": 1,
|
|
});
|
|
expect(response, isA<models.DedicatedDatabaseOperationList>());
|
|
});
|
|
|
|
test('test method getReplicas()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'replicas': 2,
|
|
'syncMode': "async",
|
|
'syncDegraded': true,
|
|
'syncAcknowledgements': 1,
|
|
'syncStandbyCount': 2,
|
|
'members': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.getReplicas(
|
|
databaseId: "<DATABASE_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/replicas",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
expect(response, isA<models.DedicatedDatabaseReplicas>());
|
|
});
|
|
|
|
test('test method getStatus()', () async {
|
|
final Map<String, dynamic> data = {
|
|
'health': "healthy",
|
|
'ready': true,
|
|
'engine': "postgresql",
|
|
'version': "17",
|
|
'uptime': 86400,
|
|
'syncMode': "async",
|
|
'syncDegraded': true,
|
|
'syncAcknowledgements': 1,
|
|
'syncStandbyCount': 2,
|
|
'replicas': [],
|
|
'volumes': [],
|
|
};
|
|
|
|
when(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: anyNamed('path'),
|
|
headers: anyNamed('headers'),
|
|
params: anyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).thenAnswer((_) async => Response(data: data));
|
|
|
|
final response = await documentsDB.getStatus(
|
|
databaseId: "<DATABASE_ID>",
|
|
);
|
|
final Map<String, dynamic> params = verify(
|
|
client.call(
|
|
HttpMethod.get,
|
|
path: "/documentsdb/%3CDATABASE_ID%3E/status",
|
|
headers: anyNamed('headers'),
|
|
params: captureAnyNamed('params'),
|
|
responseType: anyNamed('responseType'),
|
|
),
|
|
).captured.single;
|
|
expect(params, isEmpty);
|
|
expect(response, isA<models.DatabaseStatus>());
|
|
});
|
|
});
|
|
}
|