⌚ OpenOpeningstijden main server application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

add_node_test.rb 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # frozen_string_literal: true
  2. require 'test_helper'
  3. describe 'add node' do
  4. describe 'POST /nodes/:node_id' do
  5. let(:node_id) { SecureRandom.uuid }
  6. let(:lat) { 51.84 }
  7. let(:lon) { 5.86 }
  8. it 'returns success' do
  9. post_json "/nodes/#{node_id}",
  10. lat: lat,
  11. lon: lon,
  12. author_email: 'harry@example.com',
  13. contact_details: 'h.potter@example.com or visit me at home'
  14. assert_equal(201, last_response.status, "Fail with #{last_response.body}")
  15. assert_kind_of(NodeAdded, last_event(node_id))
  16. assert_equal(last_event(node_id).aggregate_id, node_id)
  17. assert_equal(
  18. last_event(node_id).body,
  19. 'lat' => lat,
  20. 'lon' => lon,
  21. 'author_email' => 'harry@example.com',
  22. 'contact_details' => 'h.potter@example.com or visit me at home'
  23. )
  24. end
  25. it 'adds a node to nodes projection' do
  26. setup_projectors
  27. post_json "/nodes/#{node_id}",
  28. lat: lat,
  29. lon: lon,
  30. author_email: 'harry@example.com',
  31. contact_details: 'h.potter@example.com or visit me at home'
  32. projector_process_event(node_id)
  33. assert_equal(
  34. Hours::Projections::Nodes::Query.handle.first[:node_id],
  35. node_id
  36. )
  37. end
  38. describe 'when the node id already exists' do
  39. before do
  40. post_json "/nodes/#{node_id}", lat: lat, lon: lon
  41. end
  42. it 'returns unprocessable entity' do
  43. post_json "/nodes/#{node_id}", lat: lat, lon: lon
  44. assert_equal(422, last_response.status)
  45. assert_equal(
  46. last_response.body,
  47. %(Unprocessable Entity: Node "#{node_id}" already exists)
  48. )
  49. end
  50. end
  51. describe 'with a missing lat or lon' do
  52. it 'returns bad request for missting lon' do
  53. post_json "/nodes/#{node_id}", lat: lat
  54. assert_equal(400, last_response.status)
  55. assert_equal last_response.body, 'Bad Request: lon is blank'
  56. end
  57. it 'returns bad request for missting lat' do
  58. post_json "/nodes/#{node_id}", lon: lon
  59. assert_equal(400, last_response.status)
  60. assert_equal last_response.body, 'Bad Request: lat is blank'
  61. end
  62. end
  63. end
  64. end