Skip to content

Commit

Permalink
Change passCase/failCase name to OK/Failure
Browse files Browse the repository at this point in the history
  • Loading branch information
YuuDaRealest committed May 9, 2024
1 parent f9fe932 commit 7259926
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void main() {
).thenAnswer(
(_) => Future.delayed(
const Duration(milliseconds: 1),
() => passCase(unit),
() => OK(unit),
),
);
forgotPasswordCubit.emailChanged(email);
Expand All @@ -70,7 +70,7 @@ void main() {
emailAddress: EmailAddress(email),
isSubmitting: false,
showErrorMessages: true,
authFailureOrSuccessOption: some(passCase(unit)),
authFailureOrSuccessOption: some(OK(unit)),
),
],
verify: (_) {
Expand All @@ -92,7 +92,7 @@ void main() {
).thenAnswer(
(_) => Future.delayed(
const Duration(milliseconds: 1),
() => failCase(const AuthFailure.serverError()),
() => failure(const AuthFailure.serverError()),
),
);
forgotPasswordCubit.emailChanged(email);
Expand All @@ -109,7 +109,7 @@ void main() {
isSubmitting: false,
showErrorMessages: true,
authFailureOrSuccessOption:
some(failCase(const AuthFailure.serverError())),
some(failure(const AuthFailure.serverError())),
),
],
verify: (_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void main() {
).thenAnswer(
(_) => Future.delayed(
const Duration(milliseconds: 1),
() => passCase(unit),
() => OK(unit),
),
);
return loginFormBloc;
Expand All @@ -88,7 +88,7 @@ void main() {
password: Password(password),
isSubmitting: false,
showErrorMessages: true,
authFailureOrSuccessOption: some(passCase(unit)),
authFailureOrSuccessOption: some(OK(unit)),
),
],
verify: (_) {
Expand All @@ -112,7 +112,7 @@ void main() {
).thenAnswer(
(_) => Future.delayed(
const Duration(milliseconds: 1),
() => failCase(const AuthFailure.serverError()),
() => failure(const AuthFailure.serverError()),
),
);
return loginFormBloc;
Expand All @@ -137,7 +137,7 @@ void main() {
isSubmitting: false,
showErrorMessages: true,
authFailureOrSuccessOption:
some(failCase(const AuthFailure.serverError())),
some(failure(const AuthFailure.serverError())),
),
],
verify: (_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void main() {
).thenAnswer(
(_) => Future.delayed(
const Duration(milliseconds: 1),
() => passCase(unit),
() => OK(unit),
),
);
return registerFormBloc;
Expand All @@ -105,7 +105,7 @@ void main() {
username: Username(username),
isSubmitting: false,
showErrorMessages: true,
authFailureOrSuccessOption: some(passCase(unit)),
authFailureOrSuccessOption: some(OK(unit)),
),
],
verify: (_) {
Expand All @@ -131,7 +131,7 @@ void main() {
).thenAnswer(
(_) => Future.delayed(
const Duration(milliseconds: 1),
() => failCase(const AuthFailure.serverError()),
() => failure(const AuthFailure.serverError()),
),
);
return registerFormBloc;
Expand All @@ -158,8 +158,7 @@ void main() {
username: Username(username),
isSubmitting: false,
showErrorMessages: true,
authFailureOrSuccessOption:
some(failCase(const AuthFailure.serverError())),
authFailureOrSuccessOption: some(fail('Test fail')),
),
],
verify: (_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void main() {
emailAddress: any(named: 'emailAddress'),
username: any(named: 'username'),
password: any(named: 'password'),
)).thenAnswer((_) async => passCase(unit));
)).thenAnswer((_) async => OK(unit));

return registerFormBloc;
},
Expand Down
16 changes: 8 additions & 8 deletions apps/mobile/packages/ddd_core/lib/src/ok_fail_test_results.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import 'package:dartz/dartz.dart';

class Fail<L, R> extends Either<L, R> {
class Failure<L, R> extends Either<L, R> {
final L _l;
const Fail(this._l);
const Failure(this._l);
L get value => _l;
@override
B fold<B>(B ifLeft(L l), B ifRight(R r)) => ifLeft(_l);
@override
bool operator ==(other) => other is Fail && other._l == _l;
bool operator ==(other) => other is Failure && other._l == _l;
@override
int get hashCode => _l.hashCode;
}

class OK<L, R> extends Either<L, R> {
class OKE<L, R> extends Either<L, R> {
final R _r;
const OK(this._r);
const OKE(this._r);
R get value => _r;
@override
B fold<B>(B ifLeft(L l), B ifRight(R r)) => ifRight(_r);
@override
bool operator ==(other) => other is OK && other._r == _r;
bool operator ==(other) => other is OKE && other._r == _r;
@override
int get hashCode => _r.hashCode;
}

Either<L, R> passCase<L, R>(R r) => new OK(r);
Either<L, R> failCase<L, R>(L l) => new Fail(l);
Either<L, R> OK<L, R>(R r) => new OKE(r);
Either<L, R> failure<L, R>(L l) => new Failure(l);

0 comments on commit 7259926

Please sign in to comment.