You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.0 KiB
141 lines
4.0 KiB
2 years ago
|
import 'package:nextcloud/nextcloud.dart';
|
||
|
import 'package:test/test.dart';
|
||
|
|
||
|
import 'helper.dart';
|
||
|
|
||
|
Future main() async {
|
||
2 years ago
|
await run(await getDockerImage());
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
Future run(final DockerImage image) async {
|
||
2 years ago
|
group('notes', () {
|
||
2 years ago
|
late DockerContainer container;
|
||
2 years ago
|
late TestNextcloudClient client;
|
||
2 years ago
|
setUp(() async {
|
||
|
container = await getDockerContainer(image);
|
||
|
client = await getTestClient(container);
|
||
|
});
|
||
|
tearDown(() => container.destroy());
|
||
2 years ago
|
|
||
2 years ago
|
test('Is supported', () async {
|
||
|
final response = await client.notes.isSupported();
|
||
|
expect(response, isTrue);
|
||
|
});
|
||
|
|
||
2 years ago
|
test('Create note favorite', () async {
|
||
|
final response = await client.notes.createNote(
|
||
|
title: 'a',
|
||
|
content: 'b',
|
||
|
category: 'c',
|
||
|
favorite: 1,
|
||
|
);
|
||
2 years ago
|
expect(response.id, isPositive);
|
||
|
expect(response.title, 'a');
|
||
|
expect(response.content, 'b');
|
||
|
expect(response.category, 'c');
|
||
|
expect(response.favorite, true);
|
||
|
expect(response.readonly, false);
|
||
|
expect(response.etag, isNotNull);
|
||
|
expect(response.modified, isNotNull);
|
||
|
});
|
||
|
|
||
2 years ago
|
test('Create note not favorite', () async {
|
||
|
final response = await client.notes.createNote(
|
||
|
title: 'a',
|
||
|
content: 'b',
|
||
|
category: 'c',
|
||
2 years ago
|
);
|
||
2 years ago
|
expect(response.id, isPositive);
|
||
|
expect(response.title, 'a');
|
||
|
expect(response.content, 'b');
|
||
|
expect(response.category, 'c');
|
||
|
expect(response.favorite, false);
|
||
|
expect(response.readonly, false);
|
||
|
expect(response.etag, isNotNull);
|
||
|
expect(response.modified, isNotNull);
|
||
|
});
|
||
|
|
||
|
test('Get notes', () async {
|
||
|
await client.notes.createNote(title: 'a');
|
||
|
await client.notes.createNote(title: 'b');
|
||
|
|
||
|
final response = await client.notes.getNotes();
|
||
2 years ago
|
expect(response, hasLength(2));
|
||
|
expect(response[0].title, 'a');
|
||
|
expect(response[1].title, 'b');
|
||
|
});
|
||
|
|
||
|
test('Get note', () async {
|
||
2 years ago
|
final response = await client.notes.getNote(
|
||
2 years ago
|
id: (await client.notes.createNote(title: 'a')).id,
|
||
2 years ago
|
);
|
||
2 years ago
|
expect(response.title, 'a');
|
||
|
});
|
||
|
|
||
|
test('Update note', () async {
|
||
2 years ago
|
final id = (await client.notes.createNote(title: 'a')).id;
|
||
2 years ago
|
await client.notes.updateNote(
|
||
|
id: id,
|
||
|
title: 'b',
|
||
2 years ago
|
);
|
||
|
|
||
2 years ago
|
final response = await client.notes.getNote(id: id);
|
||
2 years ago
|
expect(response.title, 'b');
|
||
|
});
|
||
|
|
||
|
test('Update note fail changed on server', () async {
|
||
2 years ago
|
final response = await client.notes.createNote(title: 'a');
|
||
|
await client.notes.updateNote(
|
||
2 years ago
|
id: response.id,
|
||
2 years ago
|
title: 'b',
|
||
|
ifMatch: '"${response.etag}"',
|
||
2 years ago
|
);
|
||
|
expect(
|
||
2 years ago
|
() => client.notes.updateNote(
|
||
2 years ago
|
id: response.id,
|
||
2 years ago
|
title: 'c',
|
||
|
ifMatch: '"${response.etag}"',
|
||
2 years ago
|
),
|
||
2 years ago
|
throwsA(predicate((final e) => (e! as ApiException).statusCode == 412)),
|
||
2 years ago
|
);
|
||
|
});
|
||
|
|
||
|
test('Delete note', () async {
|
||
2 years ago
|
final id = (await client.notes.createNote(title: 'a')).id;
|
||
2 years ago
|
|
||
|
var response = await client.notes.getNotes();
|
||
2 years ago
|
expect(response, hasLength(1));
|
||
|
|
||
2 years ago
|
await client.notes.deleteNote(id: id);
|
||
2 years ago
|
|
||
2 years ago
|
response = await client.notes.getNotes();
|
||
2 years ago
|
expect(response, hasLength(0));
|
||
|
});
|
||
|
|
||
|
test('Get settings', () async {
|
||
2 years ago
|
final response = await client.notes.getSettings();
|
||
2 years ago
|
expect(response.notesPath, 'Notes');
|
||
|
expect(response.fileSuffix, '.txt');
|
||
2 years ago
|
expect(response.noteMode, NotesSettings_NoteMode.edit);
|
||
2 years ago
|
});
|
||
|
|
||
2 years ago
|
test('Update settings', () async {
|
||
|
var response = await client.notes.updateSettings(
|
||
|
notesSettings: NotesSettings(
|
||
|
notesPath: 'Test Notes',
|
||
|
fileSuffix: '.md',
|
||
2 years ago
|
noteMode: NotesSettings_NoteMode.preview,
|
||
2 years ago
|
),
|
||
2 years ago
|
);
|
||
2 years ago
|
expect(response.notesPath, 'Test Notes');
|
||
|
expect(response.fileSuffix, '.md');
|
||
2 years ago
|
expect(response.noteMode, NotesSettings_NoteMode.preview);
|
||
2 years ago
|
|
||
2 years ago
|
response = await client.notes.getSettings();
|
||
2 years ago
|
expect(response.notesPath, 'Test Notes');
|
||
|
expect(response.fileSuffix, '.md');
|
||
2 years ago
|
expect(response.noteMode, NotesSettings_NoteMode.preview);
|
||
2 years ago
|
});
|
||
|
});
|
||
|
}
|