feat(authentication): remove session wrapper for AuthenticationSession

This commit is contained in:
2023-04-13 23:24:12 +02:00
parent 6556c4485f
commit b83275aaf6
32 changed files with 319 additions and 262 deletions
@@ -43,7 +43,9 @@ class TestAuthenticationCubit extends AuthenticationCubit<int> {
const Ok(null);
@override
FutureOrResult<int?> onSignInFromCache(SessionWrapper<int> wrapper) async =>
FutureOrResult<int?> onSignInFromCache(
AuthenticationSession<int> session,
) async =>
const Ok(null);
@override
@@ -53,9 +55,10 @@ class TestAuthenticationCubit extends AuthenticationCubit<int> {
void main() {
group('AuthenticationCubit<T>', () {
final MockAccount account = MockAccount();
final SessionWrapper<int> wrapper = SessionWrapper(
event: const UnknownAuthenticationEvent(),
session: Session(account: account, data: 10),
final AuthenticationSession<int> session = AuthenticationSession<int>(
latestEvent: const UnknownAuthenticationEvent(),
account: account,
data: 10,
);
late AuthenticationRepository<int> authenticationRepository;
@@ -80,14 +83,14 @@ void main() {
'emits authenticated when stream contains session',
setUp: () {
when(() => authenticationRepository.sessionStream()).thenAnswer(
(_) => Stream.fromIterable([wrapper]),
(_) => Stream.fromIterable([session]),
);
},
build: () => TestAuthenticationCubit(
authenticationRepository: authenticationRepository,
),
seed: () => const AuthenticationState.unknown(),
expect: () => [AuthenticationState<int>.authenticated(wrapper)],
expect: () => [AuthenticationState<int>.authenticated(session)],
);
blocTest<AuthenticationCubit<int>, AuthenticationState<int>>(
@@ -95,7 +98,8 @@ void main() {
setUp: () {
when(() => authenticationRepository.sessionStream()).thenAnswer(
(_) => Stream.fromIterable(
[const SessionWrapper(event: SignedOutEvent())],),
[const AuthenticationSession(latestEvent: SignedOutEvent())],
),
);
},
build: () => TestAuthenticationCubit(
@@ -27,7 +27,7 @@ void main() {
const AuthenticationState<void> state =
AuthenticationState.unauthenticated();
expect(state.status, AuthenticationStatus.unauthenticated);
expect(state.wrapper, null);
expect(state.session, null);
});
});
@@ -36,13 +36,12 @@ void main() {
final MockAccount account = MockAccount();
final AuthenticationState<void> state =
AuthenticationState.authenticated(
SessionWrapper<void>(
event: SignedInEvent(account: account),
session: Session(account: account),
AuthenticationSession.fromEvent(
SignedInEvent(account: account),
),
);
expect(state.status, AuthenticationStatus.authenticated);
expect(state.wrapper?.session?.account, account);
expect(state.session?.account, account);
});
});
@@ -52,14 +51,14 @@ void main() {
const String extra = 'AwesomeExtraData';
final AuthenticationState<String> state =
AuthenticationState.authenticated(
SessionWrapper<String>(
event: SignedInEvent(account: account),
session: Session(account: account, data: extra),
AuthenticationSession.fromEvent(
SignedInEvent(account: account),
data: extra,
),
);
expect(state.status, AuthenticationStatus.authenticated);
expect(state.wrapper?.session?.account, account);
expect(state.wrapper?.session?.data, extra);
expect(state.session?.account, account);
expect(state.session?.data, extra);
});
});
});
@@ -43,13 +43,24 @@ void main() {
when(() => authenticationRepository.sessionStream()).thenAnswer(
(_) => Stream.fromIterable([
SessionWrapper<int>(
event: SignedInFromCacheEvent(account: account),
session: Session<int>(account: account, data: 10),
AuthenticationSession.fromEvent(
SignedInFromCacheEvent(account: account),
data: 10,
)
]),
);
when(
() => authenticationRepository.currentSession(),
).thenAnswer(
(_) async => Ok(
AuthenticationSession.fromEvent(
SignedInFromCacheEvent(account: account),
data: 10,
),
),
);
when(
() => authenticationRepository.refresh(),
).thenAnswer((_) async => Ok(account));