Skip to content

Commit

Permalink
fix: a bug where the ODM does not respect JSON case renaming (firebas…
Browse files Browse the repository at this point in the history
…e#9988)

* fix: a bug where  does not respect JSON case renaming

* Add test
  • Loading branch information
rrousselGit authored Nov 24, 2022
1 parent e349728 commit 02d394b
Show file tree
Hide file tree
Showing 11 changed files with 412 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void main() {
test('supports field renaming', () async {
final collection = await initializeTest(PersonCollectionReference());

await collection.add(Person(firstName: 'A', lastName: 'A'));
final aRef = await collection.add(Person(firstName: 'A', lastName: 'A'));
await collection.add(Person(firstName: 'John', lastName: 'Doe'));
await collection.add(Person(firstName: 'John', lastName: 'Smith'));
await collection.add(Person(firstName: 'Mike', lastName: 'Doe'));
Expand Down Expand Up @@ -51,5 +51,20 @@ void main() {
.then((value) => value.docs.map((e) => e.data.firstName)),
unorderedEquals(<Object?>['John', 'Mike']),
);

await aRef.update(firstName: 'A2', lastName: 'B2');

expect(
await aRef.reference
.withConverter<Map<String, dynamic>>(
fromFirestore: (value, _) => value.data()!,
toFirestore: (value, _) => value,
)
.get(),
{
'first_name': 'A2',
'LAST_NAME': 'B2',
},
);
});
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2022, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
Expand Down Expand Up @@ -38,41 +34,45 @@ mixin _$Person {
/// @nodoc
abstract class $PersonCopyWith<$Res> {
factory $PersonCopyWith(Person value, $Res Function(Person) then) =
_$PersonCopyWithImpl<$Res>;
_$PersonCopyWithImpl<$Res, Person>;
@useResult
$Res call(
{String firstName,
@JsonKey(name: 'LAST_NAME') String lastName,
@JsonKey(ignore: true) int? ignored});
}

/// @nodoc
class _$PersonCopyWithImpl<$Res> implements $PersonCopyWith<$Res> {
class _$PersonCopyWithImpl<$Res, $Val extends Person>
implements $PersonCopyWith<$Res> {
_$PersonCopyWithImpl(this._value, this._then);

final Person _value;
// ignore: unused_field
final $Res Function(Person) _then;
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;

@pragma('vm:prefer-inline')
@override
$Res call({
Object? firstName = freezed,
Object? lastName = freezed,
Object? firstName = null,
Object? lastName = null,
Object? ignored = freezed,
}) {
return _then(_value.copyWith(
firstName: firstName == freezed
firstName: null == firstName
? _value.firstName
: firstName // ignore: cast_nullable_to_non_nullable
as String,
lastName: lastName == freezed
lastName: null == lastName
? _value.lastName
: lastName // ignore: cast_nullable_to_non_nullable
as String,
ignored: ignored == freezed
ignored: freezed == ignored
? _value.ignored
: ignored // ignore: cast_nullable_to_non_nullable
as int?,
));
) as $Val);
}
}

Expand All @@ -81,37 +81,37 @@ abstract class _$$_PersonCopyWith<$Res> implements $PersonCopyWith<$Res> {
factory _$$_PersonCopyWith(_$_Person value, $Res Function(_$_Person) then) =
__$$_PersonCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{String firstName,
@JsonKey(name: 'LAST_NAME') String lastName,
@JsonKey(ignore: true) int? ignored});
}

/// @nodoc
class __$$_PersonCopyWithImpl<$Res> extends _$PersonCopyWithImpl<$Res>
class __$$_PersonCopyWithImpl<$Res>
extends _$PersonCopyWithImpl<$Res, _$_Person>
implements _$$_PersonCopyWith<$Res> {
__$$_PersonCopyWithImpl(_$_Person _value, $Res Function(_$_Person) _then)
: super(_value, (v) => _then(v as _$_Person));

@override
_$_Person get _value => super._value as _$_Person;
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? firstName = freezed,
Object? lastName = freezed,
Object? firstName = null,
Object? lastName = null,
Object? ignored = freezed,
}) {
return _then(_$_Person(
firstName: firstName == freezed
firstName: null == firstName
? _value.firstName
: firstName // ignore: cast_nullable_to_non_nullable
as String,
lastName: lastName == freezed
lastName: null == lastName
? _value.lastName
: lastName // ignore: cast_nullable_to_non_nullable
as String,
ignored: ignored == freezed
ignored: freezed == ignored
? _value.ignored
: ignored // ignore: cast_nullable_to_non_nullable
as int?,
Expand Down Expand Up @@ -150,21 +150,20 @@ class _$_Person implements _Person {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_Person &&
const DeepCollectionEquality().equals(other.firstName, firstName) &&
const DeepCollectionEquality().equals(other.lastName, lastName) &&
const DeepCollectionEquality().equals(other.ignored, ignored));
(identical(other.firstName, firstName) ||
other.firstName == firstName) &&
(identical(other.lastName, lastName) ||
other.lastName == lastName) &&
(identical(other.ignored, ignored) || other.ignored == ignored));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(firstName),
const DeepCollectionEquality().hash(lastName),
const DeepCollectionEquality().hash(ignored));
int get hashCode => Object.hash(runtimeType, firstName, lastName, ignored);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_PersonCopyWith<_$_Person> get copyWith =>
__$$_PersonCopyWithImpl<_$_Person>(this, _$identity);

Expand Down Expand Up @@ -216,29 +215,32 @@ mixin _$PublicRedirected {
abstract class $PublicRedirectedCopyWith<$Res> {
factory $PublicRedirectedCopyWith(
PublicRedirected value, $Res Function(PublicRedirected) then) =
_$PublicRedirectedCopyWithImpl<$Res>;
_$PublicRedirectedCopyWithImpl<$Res, PublicRedirected>;
@useResult
$Res call({String value});
}

/// @nodoc
class _$PublicRedirectedCopyWithImpl<$Res>
class _$PublicRedirectedCopyWithImpl<$Res, $Val extends PublicRedirected>
implements $PublicRedirectedCopyWith<$Res> {
_$PublicRedirectedCopyWithImpl(this._value, this._then);

final PublicRedirected _value;
// ignore: unused_field
final $Res Function(PublicRedirected) _then;
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;

@pragma('vm:prefer-inline')
@override
$Res call({
Object? value = freezed,
Object? value = null,
}) {
return _then(_value.copyWith(
value: value == freezed
value: null == value
? _value.value
: value // ignore: cast_nullable_to_non_nullable
as String,
));
) as $Val);
}
}

Expand All @@ -249,26 +251,25 @@ abstract class _$$PublicRedirected2CopyWith<$Res>
_$PublicRedirected2 value, $Res Function(_$PublicRedirected2) then) =
__$$PublicRedirected2CopyWithImpl<$Res>;
@override
@useResult
$Res call({String value});
}

/// @nodoc
class __$$PublicRedirected2CopyWithImpl<$Res>
extends _$PublicRedirectedCopyWithImpl<$Res>
extends _$PublicRedirectedCopyWithImpl<$Res, _$PublicRedirected2>
implements _$$PublicRedirected2CopyWith<$Res> {
__$$PublicRedirected2CopyWithImpl(
_$PublicRedirected2 _value, $Res Function(_$PublicRedirected2) _then)
: super(_value, (v) => _then(v as _$PublicRedirected2));

@override
_$PublicRedirected2 get _value => super._value as _$PublicRedirected2;
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? value = freezed,
Object? value = null,
}) {
return _then(_$PublicRedirected2(
value: value == freezed
value: null == value
? _value.value
: value // ignore: cast_nullable_to_non_nullable
as String,
Expand Down Expand Up @@ -297,16 +298,16 @@ class _$PublicRedirected2 implements PublicRedirected2 {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PublicRedirected2 &&
const DeepCollectionEquality().equals(other.value, value));
(identical(other.value, value) || other.value == value));
}

@JsonKey(ignore: true)
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(value));
int get hashCode => Object.hash(runtimeType, value);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$PublicRedirected2CopyWith<_$PublicRedirected2> get copyWith =>
__$$PublicRedirected2CopyWithImpl<_$PublicRedirected2>(this, _$identity);

Expand Down
Loading

0 comments on commit 02d394b

Please sign in to comment.