⌚ 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.

view_proposed_nodes_test.rb 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # frozen_string_literal: true
  2. require 'test_helper'
  3. require 'json_expressions/minitest'
  4. require 'timecop'
  5. describe 'pending nodes' do
  6. describe 'GET /nodes' do
  7. let(:body) do
  8. json_fixtures('db/full.json')
  9. end
  10. let(:hm_id) { SecureRandom.uuid }
  11. let(:events) do
  12. [
  13. NodeAdded.new(
  14. aggregate_id: hm_id,
  15. body: body
  16. )
  17. ]
  18. end
  19. let(:projector) { Hours::Projections::Nodes::Projector.new }
  20. it 'returns a list of nodes' do
  21. projector.setup
  22. events.each do |event|
  23. projector.process(event)
  24. end
  25. Timecop.travel(die_wende) do
  26. assert Time.now.hour < 21 # Before 21:00
  27. assert Time.now.thursday?
  28. get '/nodes'
  29. assert_equal(200, last_response.status)
  30. expected = json_fixtures('json/nodes.json')
  31. expected[:data][0][:links][:self] = String
  32. expected[:data][0][:id] = String
  33. parsed = JSON.parse(last_response.body, symbolize_names: true)
  34. assert_json_match(expected, parsed)
  35. end
  36. end
  37. it 'on a thursday, after 21:00 it is closed' do
  38. projector.setup
  39. events.each do |event|
  40. projector.process(event)
  41. end
  42. after_hours = die_wende + (60 * 60 * 4)
  43. Timecop.travel(after_hours) do
  44. assert Time.now.hour > 21 # After 21:00
  45. get '/nodes'
  46. assert_equal(200, last_response.status)
  47. parsed = JSON.parse(last_response.body, symbolize_names: true)
  48. expected = {
  49. "data": [
  50. {
  51. attributes: { status: false }.ignore_extra_keys!
  52. }.ignore_extra_keys!
  53. ]
  54. }.ignore_extra_keys!
  55. assert_json_match(expected, parsed)
  56. end
  57. end
  58. end
  59. end