conversation_test.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # frozen_string_literal: true
  2. require 'test_helper'
  3. class PingConversationTest < Test::Unit::TestCase
  4. def test_create_conversation
  5. fake "api/ping-api/v1/conversations", method: :post, body: load_fixture('ping/conversation')
  6. conversation = ShopifyAPI::Ping::Conversation.new(
  7. topic: 'my topic',
  8. participants: [
  9. {
  10. name: 'foo',
  11. id: 'test',
  12. group: 'customer',
  13. },
  14. ]
  15. )
  16. conversation.save
  17. assert_equal "d315d4f7-53bd-49ec-8808-23f6db3c641a", conversation.id
  18. end
  19. def test_send_message
  20. fake "api/ping-api/v1/conversations/123/messages", method: :post, body: load_fixture('ping/message')
  21. conversation = ShopifyAPI::Ping::Conversation.new(id: '123')
  22. message = conversation.send_message(
  23. dedupe_key: SecureRandom.uuid,
  24. content: {
  25. text: "Hello from shopify_api",
  26. },
  27. sender_id: 'test',
  28. )
  29. assert_equal "d0c7a2e6-8084-4e79-8483-e4a1352b81f7", message.id
  30. end
  31. def test_successful_delivery
  32. fake("api/ping-api/v1/conversations/123/messages/111/delivery_confirmation",
  33. method: :post,
  34. body: load_fixture('ping/successful_delivery_confirmation'))
  35. conversation = ShopifyAPI::Ping::Conversation.new(id: '123')
  36. delivery_confirmation = conversation.successful_delivery(
  37. message_id: '111',
  38. delivery_timestamp: "2018-08-29T22:16:05.589479Z"
  39. )
  40. assert_equal("true", delivery_confirmation.delivered)
  41. assert_equal("2018-08-29T22:16:05.589479Z", delivery_confirmation.delivery_timestamp)
  42. end
  43. def test_failed_delivery
  44. fake("api/ping-api/v1/conversations/123/messages/111/delivery_confirmation",
  45. method: :post,
  46. body: load_fixture('ping/failed_delivery_confirmation'))
  47. conversation = ShopifyAPI::Ping::Conversation.new(id: '123')
  48. delivery_confirmation = conversation.failed_delivery(
  49. message_id: '111',
  50. delivery_timestamp: Time.now.to_s,
  51. details: "Integration failed to deliver message."
  52. )
  53. assert_equal("false", delivery_confirmation.delivered)
  54. assert_equal("2018-08-29T22:16:05.589479Z", delivery_confirmation.delivery_timestamp)
  55. assert_equal("Integration failed to deliver message.", delivery_confirmation.details)
  56. end
  57. end