Skip to content

Commit

Permalink
feature: added a calculated property to articles entity to get the te…
Browse files Browse the repository at this point in the history
…xt that is going to be used in ChatGPT API request
  • Loading branch information
BasakK6 committed Sep 29, 2023
1 parent 2ebcf8b commit 025191a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/features/news_feed/domain/entities/news_feed_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ class ArticlesEntity extends Equatable {
}
}

String get gptArticleContent{
if(content != null) {
return content!;
}
else {
final resultText = "${title ?? ""} ${description ?? ""}";
//remove the space characters at the beginning and end (if any)
return resultText.trim();
}
}

@override
List<Object?> get props => [
source,
Expand Down
38 changes: 38 additions & 0 deletions test/features/news_feed/domain/entities/news_feed_entity_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,44 @@ void main() {
expect(result, equals('3 Days ago'));
});
});

group("gptArticleContent tests",(){
test("should return content when content is not null", () {
const testArticlesEntity = ArticlesEntity(
title:"Title",
description: "Description",
content: "Content",
);
expect(testArticlesEntity.gptArticleContent, equals("Content"));
});

test("should return combination this string: title + space character + description when content is null", () {
const testArticlesEntity = ArticlesEntity(
title:"Title",
description: "Description",
);
expect(testArticlesEntity.gptArticleContent, equals("Title Description"));
});

test("should return empty string when both title, description and content are null", () {
const testArticlesEntity = ArticlesEntity();
expect(testArticlesEntity.gptArticleContent, equals(""));
});

test("should return title when description is null", () {
const testArticlesEntity = ArticlesEntity(
title:"Title",
);
expect(testArticlesEntity.gptArticleContent, equals('Title'));
});

test("should return description when title is null", () {
const testArticlesEntity = ArticlesEntity(
description: "Description",
);
expect(testArticlesEntity.gptArticleContent, equals('Description'));
});
});
}

/*
Expand Down

0 comments on commit 025191a

Please sign in to comment.