Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#20 get detail feed detail use case #72

Merged
merged 6 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/domain/feed/repository/feed_repository.dart
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
abstract interface class FeedRepository {}
import 'package:weaco/domain/feed/model/feed.dart';

abstract interface class FeedRepository {
Future<Feed?> getFeed({required String id});
}
16 changes: 16 additions & 0 deletions lib/domain/feed/use_case/get_detail_feed_detail_use_case.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:weaco/domain/feed/model/feed.dart';
import 'package:weaco/domain/feed/repository/feed_repository.dart';

class GetDetailFeedDetailUseCase {
final FeedRepository _feedRepository;

GetDetailFeedDetailUseCase({required FeedRepository feedRepository})
: _feedRepository = feedRepository;

/// 레포지토리에 피드 id를 전달하여 해당 피드를 가져온다.
/// @param id: 피드 id
/// @return Feed: 피드
Future<Feed?> execute({required String id}) async {
return await _feedRepository.getFeed(id: id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:weaco/domain/feed/model/feed.dart';
import 'package:weaco/domain/feed/use_case/get_detail_feed_detail_use_case.dart';
import 'package:weaco/domain/location/model/location.dart';
import 'package:weaco/domain/weather/model/weather.dart';

import '../../../mock/data/feed/repository/mock_feed_repository_impl.dart';

void main() {
group('GetDetailFeedDetailUseCase 클래스', () {
final feedRepository = MockFeedRepositoryImpl();
final getDetailFeedDetailUseCase =
GetDetailFeedDetailUseCase(feedRepository: feedRepository);

setUp(() => feedRepository.initMockData());

group('getFeed 메소드는', () {
test('파라미터로 받은 id를 FeedRepository.getFeed에 넘긴다.', () async {
// Given
const String expectedId = 'id';

// When
await getDetailFeedDetailUseCase.execute(id: expectedId);

// Then
expect(feedRepository.getFeedParamId, expectedId);
});

test('FeedRepository.getFeed를 호출하고 반환 받은 값을 그대로 반환한다.', () async {
// Given
const int expectedCallCount = 1;
final expectedFeed = Feed(
id: 'id',
imagePath: 'imagePath',
userEmail: 'userEmail',
description: 'description',
weather: Weather(
temperature: 1,
timeTemperature: DateTime.now(),
code: 1,
createdAt: DateTime.now(),
),
seasonCode: 1,
location: Location(
lat: 1,
lng: 1,
city: 'city',
createdAt: DateTime.now(),
),
createdAt: DateTime.now(),
deletedAt: null,
);
feedRepository.getFeedResult = expectedFeed;

// When
final actual = await getDetailFeedDetailUseCase.execute(id: '1');

// Then
expect(actual, expectedFeed);
expect(feedRepository.getFeedCallCount, expectedCallCount);
});
});
});
}
25 changes: 25 additions & 0 deletions test/mock/data/feed/repository/mock_feed_repository_impl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:weaco/domain/feed/model/feed.dart';
import 'package:weaco/domain/feed/repository/feed_repository.dart';

class MockFeedRepositoryImpl implements FeedRepository {
int getFeedCallCount = 0;
String getFeedParamId = '';
Feed? getFeedResult;

void initMockData() {
getFeedCallCount = 0;
getFeedParamId = '';
getFeedResult = null;
}

/// [getFeedCallCount] + 1
/// [getFeedParamId]에 [id] 저장
/// [getFeedResult] 반환
@override
Future<Feed?> getFeed({required String id}) async {
getFeedCallCount++;
getFeedParamId = id;

return getFeedResult;
}
}