From bd75d3784469ce745dde80a799494b03b9438ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9B=D0=B5=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= <71232234+leonovk@users.noreply.github.com> Date: Mon, 13 May 2024 20:41:22 +0300 Subject: [PATCH] Another test coverage (#3) --- .rspec | 2 +- spec/app/clients_controller_spec.rb | 38 +++++++++++++++++++++++++++++ spec/spec_helper.rb | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/.rspec b/.rspec index 34c5164..54a2968 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,3 @@ --format documentation ---color --require spec_helper +--order rand diff --git a/spec/app/clients_controller_spec.rb b/spec/app/clients_controller_spec.rb index 4713d97..cd4d4d7 100644 --- a/spec/app/clients_controller_spec.rb +++ b/spec/app/clients_controller_spec.rb @@ -112,4 +112,42 @@ end end end + + describe '#show' do + before do + FileUtils.cp('spec/fixtures/wg0.json', wg_conf_path) + end + + context 'when the necessary config is available' do + let(:expected_result) do + { + id: 2, + server_public_key: 'uygGKpQt7gOwrP+bqkiXytafHiM+XqFGc0jtZVJ5bnw=', + address: '10.8.0.3/24', + private_key: 'aN7ye98FKrmydwfA6tHgHE1PbiidWzUJ9cltnies8F4=', + public_key: 'hvIyIW2o8JROVKuY2yYFdUn0oA+43aLuT8KCy0YbORE=', + preshared_key: 'dVW/5kF8wnsx0zAwR4uPIa06btACxpQ/rHBL1B3qPnk=', + allowed_ips: '0.0.0.0/0, ::/0', + dns: '1.1.1.1', + persistent_keepalive: 0, + endpoint: '2.2.2.2:51820', + data: { + cheburek: 'hah' + } + } + end + + it 'returns the correct serialized config' do + result = controller.show('2') + + expect(result).to eq(expected_result.to_json) + end + end + + context 'when the required config is missing' do + it 'raises an error stating that this config is not on the server' do + expect { controller.show('17') }.to raise_error(Errors::ConfigNotFoundError) + end + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index caaaf9a..9a63fd8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,6 +9,7 @@ require_relative '../app/clients_serializer' require_relative '../app/clients_controller' require_relative '../lib/wire_guard/server' +require_relative '../app/errors/config_not_found_error' require 'super_diff/rspec'