Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize uuid, timeonly and dateonly values #15

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/src/request_information.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ class RequestInformation {
return value.toIso8601String();
}

if (value is UuidValue) {
return value.toFormattedString();
}

if (value is TimeOnly) {
return value.toRfc3339String();
}

if (value is DateOnly) {
return value.toRfc3339String();
}

if (value is Enum) {
return value.name;
}
Expand Down
46 changes: 46 additions & 0 deletions test/request_information_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:typed_data';
import 'package:kiota_abstractions/kiota_abstractions.dart';
import 'package:mockito/annotations.dart';
import 'package:test/test.dart';
import 'package:uuid/uuid.dart';

import 'request_information_test.mocks.dart';

Expand Down Expand Up @@ -92,6 +93,51 @@ void main() {
);
});

test('Sets path parameters of DateOnly type', () {
final requestInfo = RequestInformation(
httpMethod: HttpMethod.get,
urlTemplate: 'http://localhost/{date}',
);

// Act
final date = DateOnly.fromComponents(2024, 3, 20);
requestInfo.pathParameters['date'] = date;

// Assert
expect(requestInfo.uri.toString(), endsWith('2024-03-20'));
});

test('Sets path parameters of TimeOnly type', () {
final requestInfo = RequestInformation(
httpMethod: HttpMethod.get,
urlTemplate: 'http://localhost/{time}',
);

// Act
final time = TimeOnly.fromComponents(12, 34, 56);
requestInfo.pathParameters['time'] = time;

// Assert
expect(requestInfo.uri.toString(), endsWith('12%3A34%3A56'));
});

test('Sets path parameters of UuidValue type', () {
final requestInfo = RequestInformation(
httpMethod: HttpMethod.get,
urlTemplate: 'http://localhost/{uuid}',
);

// Act
final uuid = UuidValue.fromString('01234567-89ab-cdef-0123-456789abcdef');
requestInfo.pathParameters['uuid'] = uuid;

// Assert
expect(
requestInfo.uri.toString(),
endsWith('01234567-89ab-cdef-0123-456789abcdef'),
);
});

test('Sets path parameters of boolean type', () {
// Arrange as the request builders would
final requestInfo = RequestInformation(
Expand Down
Loading