github.com/lologarithm/mattermost-server@v5.3.2-0.20181002060438-c82a84ed765b+incompatible/app/notification_push_test.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package app 5 6 import ( 7 "testing" 8 9 "github.com/mattermost/mattermost-server/model" 10 "github.com/mattermost/mattermost-server/utils" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestDoesNotifyPropsAllowPushNotification(t *testing.T) { 15 tt := []struct { 16 name string 17 userNotifySetting string 18 channelNotifySetting string 19 withSystemPost bool 20 wasMentioned bool 21 isMuted bool 22 expected bool 23 }{ 24 { 25 name: "When post is a System Message and has no mentions", 26 userNotifySetting: model.USER_NOTIFY_ALL, 27 channelNotifySetting: "", 28 withSystemPost: true, 29 wasMentioned: false, 30 isMuted: false, 31 expected: false, 32 }, 33 { 34 name: "When post is a System Message and has mentions", 35 userNotifySetting: model.USER_NOTIFY_ALL, 36 channelNotifySetting: "", 37 withSystemPost: true, 38 wasMentioned: true, 39 isMuted: false, 40 expected: false, 41 }, 42 { 43 name: "When default is ALL, no channel props is set and has no mentions", 44 userNotifySetting: model.USER_NOTIFY_ALL, 45 channelNotifySetting: "", 46 withSystemPost: false, 47 wasMentioned: false, 48 isMuted: false, 49 expected: true, 50 }, 51 { 52 name: "When default is ALL, no channel props is set and has mentions", 53 userNotifySetting: model.USER_NOTIFY_ALL, 54 channelNotifySetting: "", 55 withSystemPost: false, 56 wasMentioned: true, 57 isMuted: false, 58 expected: true, 59 }, 60 { 61 name: "When default is MENTION, no channel props is set and has no mentions", 62 userNotifySetting: model.USER_NOTIFY_MENTION, 63 channelNotifySetting: "", 64 withSystemPost: false, 65 wasMentioned: false, 66 isMuted: false, 67 expected: false, 68 }, 69 { 70 name: "When default is MENTION, no channel props is set and has mentions", 71 userNotifySetting: model.USER_NOTIFY_MENTION, 72 channelNotifySetting: "", 73 withSystemPost: false, 74 wasMentioned: true, 75 isMuted: false, 76 expected: true, 77 }, 78 { 79 name: "When default is NONE, no channel props is set and has no mentions", 80 userNotifySetting: model.USER_NOTIFY_NONE, 81 channelNotifySetting: "", 82 withSystemPost: false, 83 wasMentioned: false, 84 isMuted: false, 85 expected: false, 86 }, 87 { 88 name: "When default is NONE, no channel props is set and has mentions", 89 userNotifySetting: model.USER_NOTIFY_NONE, 90 channelNotifySetting: "", 91 withSystemPost: false, 92 wasMentioned: true, 93 isMuted: false, 94 expected: false, 95 }, 96 { 97 name: "When default is ALL, channel is DEFAULT and has no mentions", 98 userNotifySetting: model.USER_NOTIFY_ALL, 99 channelNotifySetting: model.CHANNEL_NOTIFY_DEFAULT, 100 withSystemPost: false, 101 wasMentioned: false, 102 isMuted: false, 103 expected: true, 104 }, 105 { 106 name: "When default is ALL, channel is DEFAULT and has mentions", 107 userNotifySetting: model.USER_NOTIFY_ALL, 108 channelNotifySetting: model.CHANNEL_NOTIFY_DEFAULT, 109 withSystemPost: false, 110 wasMentioned: true, 111 isMuted: false, 112 expected: true, 113 }, 114 { 115 name: "When default is MENTION, channel is DEFAULT and has no mentions", 116 userNotifySetting: model.USER_NOTIFY_MENTION, 117 channelNotifySetting: model.CHANNEL_NOTIFY_DEFAULT, 118 withSystemPost: false, 119 wasMentioned: false, 120 isMuted: false, 121 expected: false, 122 }, 123 { 124 name: "When default is MENTION, channel is DEFAULT and has mentions", 125 userNotifySetting: model.USER_NOTIFY_MENTION, 126 channelNotifySetting: model.CHANNEL_NOTIFY_DEFAULT, 127 withSystemPost: false, 128 wasMentioned: true, 129 isMuted: false, 130 expected: true, 131 }, 132 { 133 name: "When default is NONE, channel is DEFAULT and has no mentions", 134 userNotifySetting: model.USER_NOTIFY_NONE, 135 channelNotifySetting: model.CHANNEL_NOTIFY_DEFAULT, 136 withSystemPost: false, 137 wasMentioned: false, 138 isMuted: false, 139 expected: false, 140 }, 141 { 142 name: "When default is NONE, channel is DEFAULT and has mentions", 143 userNotifySetting: model.USER_NOTIFY_NONE, 144 channelNotifySetting: model.CHANNEL_NOTIFY_DEFAULT, 145 withSystemPost: false, 146 wasMentioned: true, 147 isMuted: false, 148 expected: false, 149 }, 150 { 151 name: "When default is ALL, channel is ALL and has no mentions", 152 userNotifySetting: model.USER_NOTIFY_ALL, 153 channelNotifySetting: model.CHANNEL_NOTIFY_ALL, 154 withSystemPost: false, 155 wasMentioned: false, 156 isMuted: false, 157 expected: true, 158 }, 159 { 160 name: "When default is ALL, channel is ALL and has mentions", 161 userNotifySetting: model.USER_NOTIFY_ALL, 162 channelNotifySetting: model.CHANNEL_NOTIFY_ALL, 163 withSystemPost: false, 164 wasMentioned: true, 165 isMuted: false, 166 expected: true, 167 }, 168 { 169 name: "When default is MENTION, channel is ALL and has no mentions", 170 userNotifySetting: model.USER_NOTIFY_MENTION, 171 channelNotifySetting: model.CHANNEL_NOTIFY_ALL, 172 withSystemPost: false, 173 wasMentioned: false, 174 isMuted: false, 175 expected: true, 176 }, 177 { 178 name: "When default is MENTION, channel is ALL and has mentions", 179 userNotifySetting: model.USER_NOTIFY_MENTION, 180 channelNotifySetting: model.CHANNEL_NOTIFY_ALL, 181 withSystemPost: false, 182 wasMentioned: true, 183 isMuted: false, 184 expected: true, 185 }, 186 { 187 name: "When default is NONE, channel is ALL and has no mentions", 188 userNotifySetting: model.USER_NOTIFY_NONE, 189 channelNotifySetting: model.CHANNEL_NOTIFY_ALL, 190 withSystemPost: false, 191 wasMentioned: false, 192 isMuted: false, 193 expected: true, 194 }, 195 { 196 name: "When default is NONE, channel is ALL and has mentions", 197 userNotifySetting: model.USER_NOTIFY_NONE, 198 channelNotifySetting: model.CHANNEL_NOTIFY_ALL, 199 withSystemPost: false, 200 wasMentioned: true, 201 isMuted: false, 202 expected: true, 203 }, 204 { 205 name: "When default is ALL, channel is MENTION and has no mentions", 206 userNotifySetting: model.USER_NOTIFY_ALL, 207 channelNotifySetting: model.CHANNEL_NOTIFY_MENTION, 208 withSystemPost: false, 209 wasMentioned: false, 210 isMuted: false, 211 expected: false, 212 }, 213 { 214 name: "When default is ALL, channel is MENTION and has mentions", 215 userNotifySetting: model.USER_NOTIFY_ALL, 216 channelNotifySetting: model.CHANNEL_NOTIFY_MENTION, 217 withSystemPost: false, 218 wasMentioned: true, 219 isMuted: false, 220 expected: true, 221 }, 222 { 223 name: "When default is MENTION, channel is MENTION and has no mentions", 224 userNotifySetting: model.USER_NOTIFY_MENTION, 225 channelNotifySetting: model.CHANNEL_NOTIFY_MENTION, 226 withSystemPost: false, 227 wasMentioned: false, 228 isMuted: false, 229 expected: false, 230 }, 231 { 232 name: "When default is MENTION, channel is MENTION and has mentions", 233 userNotifySetting: model.USER_NOTIFY_MENTION, 234 channelNotifySetting: model.CHANNEL_NOTIFY_MENTION, 235 withSystemPost: false, 236 wasMentioned: true, 237 isMuted: false, 238 expected: true, 239 }, 240 { 241 name: "When default is NONE, channel is MENTION and has no mentions", 242 userNotifySetting: model.USER_NOTIFY_NONE, 243 channelNotifySetting: model.CHANNEL_NOTIFY_MENTION, 244 withSystemPost: false, 245 wasMentioned: false, 246 isMuted: false, 247 expected: false, 248 }, 249 { 250 name: "When default is NONE, channel is MENTION and has mentions", 251 userNotifySetting: model.USER_NOTIFY_NONE, 252 channelNotifySetting: model.CHANNEL_NOTIFY_MENTION, 253 withSystemPost: false, 254 wasMentioned: true, 255 isMuted: false, 256 expected: true, 257 }, 258 { 259 name: "When default is ALL, channel is NONE and has no mentions", 260 userNotifySetting: model.USER_NOTIFY_ALL, 261 channelNotifySetting: model.CHANNEL_NOTIFY_NONE, 262 withSystemPost: false, 263 wasMentioned: false, 264 isMuted: false, 265 expected: false, 266 }, 267 { 268 name: "When default is ALL, channel is NONE and has mentions", 269 userNotifySetting: model.USER_NOTIFY_ALL, 270 channelNotifySetting: model.CHANNEL_NOTIFY_NONE, 271 withSystemPost: false, 272 wasMentioned: true, 273 isMuted: false, 274 expected: false, 275 }, 276 { 277 name: "When default is MENTION, channel is NONE and has no mentions", 278 userNotifySetting: model.USER_NOTIFY_MENTION, 279 channelNotifySetting: model.CHANNEL_NOTIFY_NONE, 280 withSystemPost: false, 281 wasMentioned: false, 282 isMuted: false, 283 expected: false, 284 }, 285 { 286 name: "When default is MENTION, channel is NONE and has mentions", 287 userNotifySetting: model.USER_NOTIFY_MENTION, 288 channelNotifySetting: model.CHANNEL_NOTIFY_NONE, 289 withSystemPost: false, 290 wasMentioned: true, 291 isMuted: false, 292 expected: false, 293 }, 294 { 295 name: "When default is NONE, channel is NONE and has no mentions", 296 userNotifySetting: model.USER_NOTIFY_NONE, 297 channelNotifySetting: model.CHANNEL_NOTIFY_NONE, 298 withSystemPost: false, 299 wasMentioned: false, 300 isMuted: false, 301 expected: false, 302 }, 303 { 304 name: "When default is NONE, channel is NONE and has mentions", 305 userNotifySetting: model.USER_NOTIFY_NONE, 306 channelNotifySetting: model.CHANNEL_NOTIFY_NONE, 307 withSystemPost: false, 308 wasMentioned: true, 309 isMuted: false, 310 expected: false, 311 }, 312 { 313 name: "When default is ALL, and channel is MUTED", 314 userNotifySetting: model.USER_NOTIFY_ALL, 315 channelNotifySetting: "", 316 withSystemPost: false, 317 wasMentioned: false, 318 isMuted: true, 319 expected: false, 320 }, 321 } 322 323 for _, tc := range tt { 324 t.Run(tc.name, func(t *testing.T) { 325 user := &model.User{Id: model.NewId(), Email: "unit@test.com", NotifyProps: make(map[string]string)} 326 user.NotifyProps[model.PUSH_NOTIFY_PROP] = tc.userNotifySetting 327 post := &model.Post{UserId: user.Id, ChannelId: model.NewId()} 328 if tc.withSystemPost { 329 post.Type = model.POST_JOIN_CHANNEL 330 } 331 332 channelNotifyProps := make(map[string]string) 333 if tc.channelNotifySetting != "" { 334 channelNotifyProps[model.PUSH_NOTIFY_PROP] = tc.channelNotifySetting 335 } 336 if tc.isMuted { 337 channelNotifyProps[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_MENTION 338 } 339 assert.Equal(t, tc.expected, DoesNotifyPropsAllowPushNotification(user, channelNotifyProps, post, tc.wasMentioned)) 340 }) 341 } 342 } 343 344 func TestDoesStatusAllowPushNotification(t *testing.T) { 345 userId := model.NewId() 346 channelId := model.NewId() 347 348 offline := &model.Status{UserId: userId, Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""} 349 away := &model.Status{UserId: userId, Status: model.STATUS_AWAY, Manual: false, LastActivityAt: 0, ActiveChannel: ""} 350 online := &model.Status{UserId: userId, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""} 351 dnd := &model.Status{UserId: userId, Status: model.STATUS_DND, Manual: true, LastActivityAt: model.GetMillis(), ActiveChannel: ""} 352 353 tt := []struct { 354 name string 355 userNotifySetting string 356 status *model.Status 357 channelId string 358 expected bool 359 }{ 360 { 361 name: "WHEN props is ONLINE and user is offline with channel", 362 userNotifySetting: model.STATUS_ONLINE, 363 status: offline, 364 channelId: channelId, 365 expected: true, 366 }, 367 { 368 name: "WHEN props is ONLINE and user is offline without channel", 369 userNotifySetting: model.STATUS_ONLINE, 370 status: offline, 371 channelId: "", 372 expected: true, 373 }, 374 { 375 name: "WHEN props is ONLINE and user is away with channel", 376 userNotifySetting: model.STATUS_ONLINE, 377 status: away, 378 channelId: channelId, 379 expected: true, 380 }, 381 { 382 name: "WHEN props is ONLINE and user is away without channel", 383 userNotifySetting: model.STATUS_ONLINE, 384 status: away, 385 channelId: "", 386 expected: true, 387 }, 388 { 389 name: "WHEN props is ONLINE and user is online with channel", 390 userNotifySetting: model.STATUS_ONLINE, 391 status: online, 392 channelId: channelId, 393 expected: true, 394 }, 395 { 396 name: "WHEN props is ONLINE and user is online without channel", 397 userNotifySetting: model.STATUS_ONLINE, 398 status: online, 399 channelId: "", 400 expected: false, 401 }, 402 { 403 name: "WHEN props is ONLINE and user is dnd with channel", 404 userNotifySetting: model.STATUS_ONLINE, 405 status: dnd, 406 channelId: channelId, 407 expected: false, 408 }, 409 { 410 name: "WHEN props is ONLINE and user is dnd without channel", 411 userNotifySetting: model.STATUS_ONLINE, 412 status: dnd, 413 channelId: "", 414 expected: false, 415 }, 416 { 417 name: "WHEN props is AWAY and user is offline with channel", 418 userNotifySetting: model.STATUS_AWAY, 419 status: offline, 420 channelId: channelId, 421 expected: true, 422 }, 423 { 424 name: "WHEN props is AWAY and user is offline without channel", 425 userNotifySetting: model.STATUS_AWAY, 426 status: offline, 427 channelId: "", 428 expected: true, 429 }, 430 { 431 name: "WHEN props is AWAY and user is away with channel", 432 userNotifySetting: model.STATUS_AWAY, 433 status: away, 434 channelId: channelId, 435 expected: true, 436 }, 437 { 438 name: "WHEN props is AWAY and user is away without channel", 439 userNotifySetting: model.STATUS_AWAY, 440 status: away, 441 channelId: "", 442 expected: true, 443 }, 444 { 445 name: "WHEN props is AWAY and user is online with channel", 446 userNotifySetting: model.STATUS_AWAY, 447 status: online, 448 channelId: channelId, 449 expected: false, 450 }, 451 { 452 name: "WHEN props is AWAY and user is online without channel", 453 userNotifySetting: model.STATUS_AWAY, 454 status: online, 455 channelId: "", 456 expected: false, 457 }, 458 { 459 name: "WHEN props is AWAY and user is dnd with channel", 460 userNotifySetting: model.STATUS_AWAY, 461 status: dnd, 462 channelId: channelId, 463 expected: false, 464 }, 465 { 466 name: "WHEN props is AWAY and user is dnd without channel", 467 userNotifySetting: model.STATUS_AWAY, 468 status: dnd, 469 channelId: "", 470 expected: false, 471 }, 472 { 473 name: "WHEN props is OFFLINE and user is offline with channel", 474 userNotifySetting: model.STATUS_OFFLINE, 475 status: offline, 476 channelId: channelId, 477 expected: true, 478 }, 479 { 480 name: "WHEN props is OFFLINE and user is offline without channel", 481 userNotifySetting: model.STATUS_OFFLINE, 482 status: offline, 483 channelId: "", 484 expected: true, 485 }, 486 { 487 name: "WHEN props is OFFLINE and user is away with channel", 488 userNotifySetting: model.STATUS_OFFLINE, 489 status: away, 490 channelId: channelId, 491 expected: false, 492 }, 493 { 494 name: "WHEN props is OFFLINE and user is away without channel", 495 userNotifySetting: model.STATUS_OFFLINE, 496 status: away, 497 channelId: "", 498 expected: false, 499 }, 500 { 501 name: "WHEN props is OFFLINE and user is online with channel", 502 userNotifySetting: model.STATUS_OFFLINE, 503 status: online, 504 channelId: channelId, 505 expected: false, 506 }, 507 { 508 name: "WHEN props is OFFLINE and user is online without channel", 509 userNotifySetting: model.STATUS_OFFLINE, 510 status: online, 511 channelId: "", 512 expected: false, 513 }, 514 { 515 name: "WHEN props is OFFLINE and user is dnd with channel", 516 userNotifySetting: model.STATUS_OFFLINE, 517 status: dnd, 518 channelId: channelId, 519 expected: false, 520 }, 521 { 522 name: "WHEN props is OFFLINE and user is dnd without channel", 523 userNotifySetting: model.STATUS_OFFLINE, 524 status: dnd, 525 channelId: "", 526 expected: false, 527 }, 528 } 529 530 for _, tc := range tt { 531 t.Run(tc.name, func(t *testing.T) { 532 userNotifyProps := make(map[string]string) 533 userNotifyProps["push_status"] = tc.userNotifySetting 534 assert.Equal(t, tc.expected, DoesStatusAllowPushNotification(userNotifyProps, tc.status, tc.channelId)) 535 }) 536 } 537 } 538 539 func TestGetPushNotificationMessage(t *testing.T) { 540 th := Setup() 541 defer th.TearDown() 542 543 for name, tc := range map[string]struct { 544 Message string 545 explicitMention bool 546 channelWideMention bool 547 HasFiles bool 548 replyToThreadType string 549 Locale string 550 PushNotificationContents string 551 ChannelType string 552 553 ExpectedMessage string 554 }{ 555 "full message, public channel, no mention": { 556 Message: "this is a message", 557 ChannelType: model.CHANNEL_OPEN, 558 ExpectedMessage: "@user: this is a message", 559 }, 560 "full message, public channel, mention": { 561 Message: "this is a message", 562 explicitMention: true, 563 ChannelType: model.CHANNEL_OPEN, 564 ExpectedMessage: "@user: this is a message", 565 }, 566 "full message, public channel, channel wide mention": { 567 Message: "this is a message", 568 channelWideMention: true, 569 ChannelType: model.CHANNEL_OPEN, 570 ExpectedMessage: "@user: this is a message", 571 }, 572 "full message, public channel, commented on post": { 573 Message: "this is a message", 574 replyToThreadType: THREAD_ROOT, 575 ChannelType: model.CHANNEL_OPEN, 576 ExpectedMessage: "@user: this is a message", 577 }, 578 "full message, public channel, commented on thread": { 579 Message: "this is a message", 580 replyToThreadType: THREAD_ANY, 581 ChannelType: model.CHANNEL_OPEN, 582 ExpectedMessage: "@user: this is a message", 583 }, 584 "full message, private channel, no mention": { 585 Message: "this is a message", 586 ChannelType: model.CHANNEL_PRIVATE, 587 ExpectedMessage: "@user: this is a message", 588 }, 589 "full message, private channel, mention": { 590 Message: "this is a message", 591 explicitMention: true, 592 ChannelType: model.CHANNEL_PRIVATE, 593 ExpectedMessage: "@user: this is a message", 594 }, 595 "full message, private channel, commented on post": { 596 Message: "this is a message", 597 replyToThreadType: THREAD_ROOT, 598 ChannelType: model.CHANNEL_PRIVATE, 599 ExpectedMessage: "@user: this is a message", 600 }, 601 "full message, private channel, commented on thread": { 602 Message: "this is a message", 603 replyToThreadType: THREAD_ANY, 604 ChannelType: model.CHANNEL_PRIVATE, 605 ExpectedMessage: "@user: this is a message", 606 }, 607 "full message, group message channel, no mention": { 608 Message: "this is a message", 609 ChannelType: model.CHANNEL_GROUP, 610 ExpectedMessage: "@user: this is a message", 611 }, 612 "full message, group message channel, mention": { 613 Message: "this is a message", 614 explicitMention: true, 615 ChannelType: model.CHANNEL_GROUP, 616 ExpectedMessage: "@user: this is a message", 617 }, 618 "full message, group message channel, commented on post": { 619 Message: "this is a message", 620 replyToThreadType: THREAD_ROOT, 621 ChannelType: model.CHANNEL_GROUP, 622 ExpectedMessage: "@user: this is a message", 623 }, 624 "full message, group message channel, commented on thread": { 625 Message: "this is a message", 626 replyToThreadType: THREAD_ANY, 627 ChannelType: model.CHANNEL_GROUP, 628 ExpectedMessage: "@user: this is a message", 629 }, 630 "full message, direct message channel, no mention": { 631 Message: "this is a message", 632 ChannelType: model.CHANNEL_DIRECT, 633 ExpectedMessage: "this is a message", 634 }, 635 "full message, direct message channel, mention": { 636 Message: "this is a message", 637 explicitMention: true, 638 ChannelType: model.CHANNEL_DIRECT, 639 ExpectedMessage: "this is a message", 640 }, 641 "full message, direct message channel, commented on post": { 642 Message: "this is a message", 643 replyToThreadType: THREAD_ROOT, 644 ChannelType: model.CHANNEL_DIRECT, 645 ExpectedMessage: "this is a message", 646 }, 647 "full message, direct message channel, commented on thread": { 648 Message: "this is a message", 649 replyToThreadType: THREAD_ANY, 650 ChannelType: model.CHANNEL_DIRECT, 651 ExpectedMessage: "this is a message", 652 }, 653 "generic message with channel, public channel, no mention": { 654 Message: "this is a message", 655 PushNotificationContents: model.GENERIC_NOTIFICATION, 656 ChannelType: model.CHANNEL_OPEN, 657 ExpectedMessage: "@user posted a message.", 658 }, 659 "generic message with channel, public channel, mention": { 660 Message: "this is a message", 661 explicitMention: true, 662 PushNotificationContents: model.GENERIC_NOTIFICATION, 663 ChannelType: model.CHANNEL_OPEN, 664 ExpectedMessage: "@user mentioned you.", 665 }, 666 "generic message with channel, public channel, channel wide mention": { 667 Message: "this is a message", 668 channelWideMention: true, 669 PushNotificationContents: model.GENERIC_NOTIFICATION, 670 ChannelType: model.CHANNEL_OPEN, 671 ExpectedMessage: "@user notified the channel.", 672 }, 673 "generic message, public channel, commented on post": { 674 Message: "this is a message", 675 replyToThreadType: THREAD_ROOT, 676 PushNotificationContents: model.GENERIC_NOTIFICATION, 677 ChannelType: model.CHANNEL_OPEN, 678 ExpectedMessage: "@user commented on your post.", 679 }, 680 "generic message, public channel, commented on thread": { 681 Message: "this is a message", 682 replyToThreadType: THREAD_ANY, 683 PushNotificationContents: model.GENERIC_NOTIFICATION, 684 ChannelType: model.CHANNEL_OPEN, 685 ExpectedMessage: "@user commented on a thread you participated in.", 686 }, 687 "generic message with channel, private channel, no mention": { 688 Message: "this is a message", 689 PushNotificationContents: model.GENERIC_NOTIFICATION, 690 ChannelType: model.CHANNEL_PRIVATE, 691 ExpectedMessage: "@user posted a message.", 692 }, 693 "generic message with channel, private channel, mention": { 694 Message: "this is a message", 695 explicitMention: true, 696 PushNotificationContents: model.GENERIC_NOTIFICATION, 697 ChannelType: model.CHANNEL_PRIVATE, 698 ExpectedMessage: "@user mentioned you.", 699 }, 700 "generic message with channel, private channel, channel wide mention": { 701 Message: "this is a message", 702 channelWideMention: true, 703 PushNotificationContents: model.GENERIC_NOTIFICATION, 704 ChannelType: model.CHANNEL_PRIVATE, 705 ExpectedMessage: "@user notified the channel.", 706 }, 707 "generic message, public private, commented on post": { 708 Message: "this is a message", 709 replyToThreadType: THREAD_ROOT, 710 PushNotificationContents: model.GENERIC_NOTIFICATION, 711 ChannelType: model.CHANNEL_PRIVATE, 712 ExpectedMessage: "@user commented on your post.", 713 }, 714 "generic message, public private, commented on thread": { 715 Message: "this is a message", 716 replyToThreadType: THREAD_ANY, 717 PushNotificationContents: model.GENERIC_NOTIFICATION, 718 ChannelType: model.CHANNEL_PRIVATE, 719 ExpectedMessage: "@user commented on a thread you participated in.", 720 }, 721 "generic message with channel, group message channel, no mention": { 722 Message: "this is a message", 723 PushNotificationContents: model.GENERIC_NOTIFICATION, 724 ChannelType: model.CHANNEL_GROUP, 725 ExpectedMessage: "@user posted a message.", 726 }, 727 "generic message with channel, group message channel, mention": { 728 Message: "this is a message", 729 explicitMention: true, 730 PushNotificationContents: model.GENERIC_NOTIFICATION, 731 ChannelType: model.CHANNEL_GROUP, 732 ExpectedMessage: "@user mentioned you.", 733 }, 734 "generic message with channel, group message channel, channel wide mention": { 735 Message: "this is a message", 736 channelWideMention: true, 737 PushNotificationContents: model.GENERIC_NOTIFICATION, 738 ChannelType: model.CHANNEL_GROUP, 739 ExpectedMessage: "@user notified the channel.", 740 }, 741 "generic message, group message channel, commented on post": { 742 Message: "this is a message", 743 replyToThreadType: THREAD_ROOT, 744 PushNotificationContents: model.GENERIC_NOTIFICATION, 745 ChannelType: model.CHANNEL_GROUP, 746 ExpectedMessage: "@user commented on your post.", 747 }, 748 "generic message, group message channel, commented on thread": { 749 Message: "this is a message", 750 replyToThreadType: THREAD_ANY, 751 PushNotificationContents: model.GENERIC_NOTIFICATION, 752 ChannelType: model.CHANNEL_GROUP, 753 ExpectedMessage: "@user commented on a thread you participated in.", 754 }, 755 "generic message with channel, direct message channel, no mention": { 756 Message: "this is a message", 757 PushNotificationContents: model.GENERIC_NOTIFICATION, 758 ChannelType: model.CHANNEL_DIRECT, 759 ExpectedMessage: "sent you a message.", 760 }, 761 "generic message with channel, direct message channel, mention": { 762 Message: "this is a message", 763 explicitMention: true, 764 PushNotificationContents: model.GENERIC_NOTIFICATION, 765 ChannelType: model.CHANNEL_DIRECT, 766 ExpectedMessage: "sent you a message.", 767 }, 768 "generic message with channel, direct message channel, channel wide mention": { 769 Message: "this is a message", 770 channelWideMention: true, 771 PushNotificationContents: model.GENERIC_NOTIFICATION, 772 ChannelType: model.CHANNEL_DIRECT, 773 ExpectedMessage: "sent you a message.", 774 }, 775 "generic message, direct message channel, commented on post": { 776 Message: "this is a message", 777 replyToThreadType: THREAD_ROOT, 778 PushNotificationContents: model.GENERIC_NOTIFICATION, 779 ChannelType: model.CHANNEL_DIRECT, 780 ExpectedMessage: "sent you a message.", 781 }, 782 "generic message, direct message channel, commented on thread": { 783 Message: "this is a message", 784 replyToThreadType: THREAD_ANY, 785 PushNotificationContents: model.GENERIC_NOTIFICATION, 786 ChannelType: model.CHANNEL_DIRECT, 787 ExpectedMessage: "sent you a message.", 788 }, 789 "generic message without channel, public channel, no mention": { 790 Message: "this is a message", 791 PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, 792 ChannelType: model.CHANNEL_OPEN, 793 ExpectedMessage: "@user posted a message.", 794 }, 795 "generic message without channel, public channel, mention": { 796 Message: "this is a message", 797 explicitMention: true, 798 PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, 799 ChannelType: model.CHANNEL_OPEN, 800 ExpectedMessage: "@user mentioned you.", 801 }, 802 "generic message without channel, private channel, no mention": { 803 Message: "this is a message", 804 PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, 805 ChannelType: model.CHANNEL_PRIVATE, 806 ExpectedMessage: "@user posted a message.", 807 }, 808 "generic message without channel, private channel, mention": { 809 Message: "this is a message", 810 explicitMention: true, 811 PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, 812 ChannelType: model.CHANNEL_PRIVATE, 813 ExpectedMessage: "@user mentioned you.", 814 }, 815 "generic message without channel, group message channel, no mention": { 816 Message: "this is a message", 817 PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, 818 ChannelType: model.CHANNEL_GROUP, 819 ExpectedMessage: "@user posted a message.", 820 }, 821 "generic message without channel, group message channel, mention": { 822 Message: "this is a message", 823 explicitMention: true, 824 PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, 825 ChannelType: model.CHANNEL_GROUP, 826 ExpectedMessage: "@user mentioned you.", 827 }, 828 "generic message without channel, direct message channel, no mention": { 829 Message: "this is a message", 830 PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, 831 ChannelType: model.CHANNEL_DIRECT, 832 ExpectedMessage: "sent you a message.", 833 }, 834 "generic message without channel, direct message channel, mention": { 835 Message: "this is a message", 836 explicitMention: true, 837 PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, 838 ChannelType: model.CHANNEL_DIRECT, 839 ExpectedMessage: "sent you a message.", 840 }, 841 "only files, public channel": { 842 HasFiles: true, 843 ChannelType: model.CHANNEL_OPEN, 844 ExpectedMessage: "@user attached a file.", 845 }, 846 "only files, private channel": { 847 HasFiles: true, 848 ChannelType: model.CHANNEL_PRIVATE, 849 ExpectedMessage: "@user attached a file.", 850 }, 851 "only files, group message channel": { 852 HasFiles: true, 853 ChannelType: model.CHANNEL_GROUP, 854 ExpectedMessage: "@user attached a file.", 855 }, 856 "only files, direct message channel": { 857 HasFiles: true, 858 ChannelType: model.CHANNEL_DIRECT, 859 ExpectedMessage: "attached a file.", 860 }, 861 "only files without channel, public channel": { 862 HasFiles: true, 863 PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, 864 ChannelType: model.CHANNEL_OPEN, 865 ExpectedMessage: "@user attached a file.", 866 }, 867 } { 868 t.Run(name, func(t *testing.T) { 869 locale := tc.Locale 870 if locale == "" { 871 locale = "en" 872 } 873 874 pushNotificationContents := tc.PushNotificationContents 875 if pushNotificationContents == "" { 876 pushNotificationContents = model.FULL_NOTIFICATION 877 } 878 879 th.App.UpdateConfig(func(cfg *model.Config) { 880 *cfg.EmailSettings.PushNotificationContents = pushNotificationContents 881 }) 882 883 if actualMessage := th.App.getPushNotificationMessage( 884 tc.Message, 885 tc.explicitMention, 886 tc.channelWideMention, 887 tc.HasFiles, 888 "user", 889 "channel", 890 tc.ChannelType, 891 tc.replyToThreadType, 892 utils.GetUserTranslations(locale), 893 ); actualMessage != tc.ExpectedMessage { 894 t.Fatalf("Received incorrect push notification message `%v`, expected `%v`", actualMessage, tc.ExpectedMessage) 895 } 896 }) 897 } 898 }