Skip to content

Commit f777343

Browse files
authored
Merge pull request #136 from matsumatsu20/bugfix/notification-own-comment
ALIS-1119: Don't create notifications when add comment on own articles.
2 parents 61948db + 92f625d commit f777343

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/handlers/me/articles/comments/create/me_articles_comments_create.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ def exec_main_proc(self):
6060
article_info_table = self.dynamodb.Table(os.environ['ARTICLE_INFO_TABLE_NAME'])
6161
article_info = article_info_table.get_item(Key={'article_id': self.params['article_id']})['Item']
6262

63-
self.__create_comment_notification(article_info, comment_id, user_id)
64-
self.__update_unread_notification_manager(article_info)
63+
if self.__is_notifiable_comment(article_info, user_id):
64+
self.__create_comment_notification(article_info, comment_id, user_id)
65+
self.__update_unread_notification_manager(article_info)
6566

6667
except Exception as err:
6768
logging.fatal(err)
@@ -72,6 +73,9 @@ def exec_main_proc(self):
7273
'body': json.dumps({'comment_id': comment_id})
7374
}
7475

76+
def __is_notifiable_comment(self, article_info, user_id):
77+
return False if article_info['user_id'] == user_id else True
78+
7579
def __create_comment_notification(self, article_info, comment_id, user_id):
7680
notification_table = self.dynamodb.Table(os.environ['NOTIFICATION_TABLE_NAME'])
7781
notification_id = '-'.join(

tests/handlers/me/articles/comments/create/test_me_articles_comments_create.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,45 @@ def test_main_ok_already_commented_by_myself(self):
170170
self.assertEqual(len(comment_after) - len(comment_before), 1)
171171
self.assertIsNotNone(comment)
172172

173+
@patch('me_articles_comments_create.MeArticlesCommentsCreate._MeArticlesCommentsCreate__generate_comment_id',
174+
MagicMock(return_value='PIYOPIYO'))
175+
def test_main_ok_with_adding_comment_on_own_article(self):
176+
params = {
177+
'pathParameters': {
178+
'article_id': 'publicId0001'
179+
},
180+
'body': {
181+
'text': 'A' * 400,
182+
},
183+
'requestContext': {
184+
'authorizer': {
185+
'claims': {
186+
'cognito:username': 'article_user01'
187+
}
188+
}
189+
}
190+
}
191+
192+
params['body'] = json.dumps(params['body'])
193+
194+
comment_before = self.comment_table.scan()['Items']
195+
notification_before = self.notification_table.scan()['Items']
196+
unread_notification_manager_before = self.unread_notification_manager_table.scan()['Items']
197+
198+
response = MeArticlesCommentsCreate(params, {}, self.dynamodb).main()
199+
200+
comment_after = self.comment_table.scan()['Items']
201+
notification_after = self.notification_table.scan()['Items']
202+
unread_notification_manager_after = self.unread_notification_manager_table.scan()['Items']
203+
204+
comment = self.comment_table.get_item(Key={'comment_id': 'PIYOPIYO'}).get('Item')
205+
206+
self.assertEqual(response['statusCode'], 200)
207+
self.assertIsNotNone(comment)
208+
self.assertEqual(len(comment_after) - len(comment_before), 1)
209+
self.assertEqual(len(notification_after) - len(notification_before), 0)
210+
self.assertEqual(len(unread_notification_manager_after) - len(unread_notification_manager_before), 0)
211+
173212
def test_call_validate_comment_existence(self):
174213
params = {
175214
'pathParameters': {

0 commit comments

Comments
 (0)