A framework for building convergent cross-platform Nextcloud clients using Flutter.
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.

181 lines
5.3 KiB

2 years ago
import 'package:nextcloud/nextcloud.dart';
import 'package:test/test.dart';
import 'helper.dart';
Future main() async {
final dockerImageName = await TestHelper.prepareDockerImage(apps: ['notes']);
group('notes', () {
late TestNextcloudClient client;
setUp(() async {
client = await TestHelper.getPreparedClient(dockerImageName);
});
tearDown(() => client.destroy());
test('Create note', () async {
final response = (await validateResponse<NotesNote, void>(
client.notes,
client.notes.createNoteWithHttpInfo(
title: 'a',
content: 'b',
category: 'c',
favorite: true,
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);
});
test('List notes', () async {
await validateResponse<NotesNote, void>(
client.notes,
client.notes.createNoteWithHttpInfo(title: 'a'),
2 years ago
);
await validateResponse<NotesNote, void>(
client.notes,
client.notes.createNoteWithHttpInfo(title: 'b'),
2 years ago
);
final response = (await validateResponse<List<NotesNote>, NotesNote>(
client.notes,
client.notes.getNotesWithHttpInfo(),
))!;
expect(response, hasLength(2));
expect(response[0].title, 'a');
expect(response[1].title, 'b');
});
test('Get note', () async {
final id = (await validateResponse<NotesNote, void>(
client.notes,
client.notes.createNoteWithHttpInfo(title: 'a'),
2 years ago
))!
.id!;
final response = (await validateResponse<NotesNote, void>(
client.notes,
client.notes.getNoteWithHttpInfo(id),
))!;
expect(response.title, 'a');
});
test('Update note', () async {
final id = (await validateResponse<NotesNote, void>(
client.notes,
client.notes.createNoteWithHttpInfo(title: 'a'),
2 years ago
))!
.id!;
await validateResponse<NotesNote, void>(
client.notes,
client.notes.updateNoteWithHttpInfo(
id,
title: 'b',
),
2 years ago
);
final response = (await validateResponse<NotesNote, void>(
client.notes,
client.notes.getNoteWithHttpInfo(id),
))!;
expect(response.title, 'b');
});
test('Update note fail changed on server', () async {
final response = (await validateResponse<NotesNote, void>(
client.notes,
client.notes.createNoteWithHttpInfo(title: 'a'),
2 years ago
))!;
await validateResponse<NotesNote, void>(
client.notes,
client.notes.updateNoteWithHttpInfo(
response.id!,
title: 'b',
2 years ago
ifMatch: '"${response.etag}"',
),
);
expect(
() => validateResponse<NotesNote, void>(
client.notes,
client.notes.updateNoteWithHttpInfo(
response.id!,
title: 'c',
2 years ago
ifMatch: '"${response.etag}"',
),
),
throwsA(predicate((final e) => (e! as ApiException).code == 412)),
);
});
test('Delete note', () async {
final id = (await validateResponse<NotesNote, void>(
client.notes,
client.notes.createNoteWithHttpInfo(title: 'a'),
2 years ago
))!
.id!;
var response = (await validateResponse<List<NotesNote>, NotesNote>(
client.notes,
client.notes.getNotesWithHttpInfo(),
))!;
expect(response, hasLength(1));
await validateResponse<List<NotesNote>, NotesNote>(
client.notes,
client.notes.deleteNoteWithHttpInfo(id),
);
response = (await validateResponse<List<NotesNote>, NotesNote>(
client.notes,
client.notes.getNotesWithHttpInfo(),
))!;
expect(response, hasLength(0));
});
test('Get settings', () async {
final response = (await validateResponse<NotesSettings, void>(
client.notes,
client.notes.getSettingsWithHttpInfo(),
))!;
expect(response.notesPath, 'Notes');
expect(response.fileSuffix, '.txt');
expect(response.noteMode, NotesSettingsNoteModeEnum.edit);
});
test('Set settings', () async {
var response = (await validateResponse<NotesSettings, NotesSettings>(
client.notes,
client.notes.getSettingsWithHttpInfo(),
))!;
response = (await validateResponse<NotesSettings, NotesSettings>(
client.notes,
client.notes.updateSettingsWithHttpInfo(
NotesSettings(
notesPath: 'Test Notes',
fileSuffix: '.md',
noteMode: NotesSettingsNoteModeEnum.preview,
),
),
))!;
expect(response.notesPath, 'Test Notes');
expect(response.fileSuffix, '.md');
expect(response.noteMode, NotesSettingsNoteModeEnum.preview);
response = (await validateResponse<NotesSettings, NotesSettings>(
client.notes,
client.notes.getSettingsWithHttpInfo(),
))!;
expect(response.notesPath, 'Test Notes');
expect(response.fileSuffix, '.md');
expect(response.noteMode, NotesSettingsNoteModeEnum.preview);
});
});
}