refactor(frontend): adapt to RESTful API routes
This commit is contained in:
@@ -34,16 +34,13 @@ void main() {
|
||||
});
|
||||
|
||||
group('AuthRepositoryImpl', () {
|
||||
test('signupStart calls api and returns response', () async {
|
||||
when(() => mockApi.signupStart(any())).thenAnswer(
|
||||
(_) async => const SignupStartResponse(
|
||||
status: 'pending_verification',
|
||||
email: 'test@example.com',
|
||||
message: 'Verification code sent',
|
||||
),
|
||||
test('createVerification calls api and returns response', () async {
|
||||
when(() => mockApi.createVerification(any())).thenAnswer(
|
||||
(_) async =>
|
||||
const VerificationCreateResponse(email: 'test@example.com'),
|
||||
);
|
||||
|
||||
final result = await repository.signupStart(
|
||||
final result = await repository.createVerification(
|
||||
const SignupStartRequest(
|
||||
username: 'testuser',
|
||||
email: 'test@example.com',
|
||||
@@ -51,12 +48,12 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
expect(result.status, 'pending_verification');
|
||||
verify(() => mockApi.signupStart(any())).called(1);
|
||||
expect(result.email, 'test@example.com');
|
||||
verify(() => mockApi.createVerification(any())).called(1);
|
||||
});
|
||||
|
||||
test('login calls api and saves tokens', () async {
|
||||
when(() => mockApi.login(any())).thenAnswer(
|
||||
test('createSession calls api and saves tokens', () async {
|
||||
when(() => mockApi.createSession(any())).thenAnswer(
|
||||
(_) async => AuthResponse(
|
||||
accessToken: 'access_token',
|
||||
refreshToken: 'refresh_token',
|
||||
@@ -72,7 +69,7 @@ void main() {
|
||||
),
|
||||
).thenAnswer((_) async {});
|
||||
|
||||
final result = await repository.login(
|
||||
final result = await repository.createSession(
|
||||
const LoginRequest(email: 'test@example.com', password: 'password123'),
|
||||
);
|
||||
|
||||
@@ -85,21 +82,24 @@ void main() {
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('logout calls api with refresh token and clears storage', () async {
|
||||
when(
|
||||
() => mockStorage.getRefreshToken(),
|
||||
).thenAnswer((_) async => 'refresh_token');
|
||||
when(() => mockApi.logout(any())).thenAnswer((_) async {});
|
||||
when(() => mockStorage.clear()).thenAnswer((_) async {});
|
||||
test(
|
||||
'deleteSession calls api with refresh token and clears storage',
|
||||
() async {
|
||||
when(
|
||||
() => mockStorage.getRefreshToken(),
|
||||
).thenAnswer((_) async => 'refresh_token');
|
||||
when(() => mockApi.deleteSession(any())).thenAnswer((_) async {});
|
||||
when(() => mockStorage.clear()).thenAnswer((_) async {});
|
||||
|
||||
await repository.logout();
|
||||
await repository.deleteSession();
|
||||
|
||||
verify(() => mockApi.logout(any())).called(1);
|
||||
verify(() => mockStorage.clear()).called(1);
|
||||
});
|
||||
verify(() => mockApi.deleteSession(any())).called(1);
|
||||
verify(() => mockStorage.clear()).called(1);
|
||||
},
|
||||
);
|
||||
|
||||
test('refresh saves new tokens', () async {
|
||||
when(() => mockApi.refresh(any())).thenAnswer(
|
||||
test('refreshSession saves new tokens', () async {
|
||||
when(() => mockApi.refreshSession(any())).thenAnswer(
|
||||
(_) async => AuthResponse(
|
||||
accessToken: 'new_access',
|
||||
refreshToken: 'new_refresh',
|
||||
@@ -115,7 +115,7 @@ void main() {
|
||||
),
|
||||
).thenAnswer((_) async {});
|
||||
|
||||
final result = await repository.refresh('old_refresh');
|
||||
final result = await repository.refreshSession('old_refresh');
|
||||
|
||||
expect(result.accessToken, 'new_access');
|
||||
verify(
|
||||
|
||||
Reference in New Issue
Block a user