Skip to content

Commit

Permalink
chore: DocumentSchemaDto tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtscalac committed Jan 16, 2025
1 parent d3e2940 commit 63979b8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,28 @@ final class DocumentPropertySchemaDto {
final List<String>? order;

const DocumentPropertySchemaDto({
this.ref,
this.types,
this.format,
this.contentMediaType,
this.title,
this.description,
this.defaultValue,
this.guidance,
this.constValue,
this.enumValues,
this.properties,
this.items,
this.minimum,
this.maximum,
this.minLength,
this.maxLength,
this.maxItems,
this.minItems,
this.oneOf,
this.required,
this.order,
this.pattern,
required this.ref,
required this.types,
required this.format,
required this.contentMediaType,
required this.title,
required this.description,
required this.defaultValue,
required this.guidance,
required this.constValue,
required this.enumValues,
required this.properties,
required this.items,
required this.minimum,
required this.maximum,
required this.minLength,
required this.maxLength,
required this.maxItems,
required this.minItems,
required this.oneOf,
required this.required,
required this.order,
required this.pattern,
});

factory DocumentPropertySchemaDto.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -208,6 +208,9 @@ final class DocumentPropertySchemaDto {
title: title ?? other.title,
description: description ?? other.description,
defaultValue: defaultValue ?? other.defaultValue,
guidance: guidance ?? other.guidance,
constValue: constValue ?? other.constValue,
enumValues: enumValues ?? other.enumValues,
properties: mergedProperties,
items: mergedItems,
minimum: minimum ?? other.minimum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:json_annotation/json_annotation.dart';

part 'document_schema_dto.g.dart';

@JsonSerializable()
@JsonSerializable(includeIfNull: false)
final class DocumentSchemaDto {
@JsonKey(name: r'$schema')
final String schema;
Expand Down Expand Up @@ -36,6 +36,7 @@ final class DocumentSchemaDto {
required this.order,
required this.propertiesSchema,
});

factory DocumentSchemaDto.fromJson(Map<String, dynamic> json) {
final segmentsMap = json['properties'] as Map<String, dynamic>;
json['propertiesSchema'] =
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'dart:convert';

import 'package:catalyst_voices_repositories/src/dto/document/schema/document_schema_dto.dart';
import 'package:test/test.dart';

import '../../../helpers/read_json.dart';

void main() {
group(DocumentSchemaDto, () {
const schemaPath =
'test/assets/0ce8ab38-9258-4fbc-a62e-7faa6e58318f.schema.json';

late Map<String, dynamic> schemaJson;

setUpAll(() {
schemaJson = json.decode(readJson(schemaPath)) as Map<String, dynamic>;
});

test('document schema can be decoded and encoded', () {
final originalSchema = DocumentSchemaDto.fromJson(schemaJson);
final originalModel = originalSchema.toModel();
expect(originalModel.properties, isNotEmpty);

final encodedSchema = originalSchema.toJson();
expect(encodedSchema, isNotEmpty);

final redecodedSchema = DocumentSchemaDto.fromJson(encodedSchema);
final redecodedModel = redecodedSchema.toModel();
expect(redecodedModel, equals(originalModel));
});
});
}

0 comments on commit 63979b8

Please sign in to comment.