Added some more unit tests
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2025-08-20 10:34:41 -04:00
parent 8b2c152803
commit 8c5f510c70
3 changed files with 130 additions and 13 deletions

View File

@@ -1,9 +1,10 @@
# frozen_string_literal: true
require_relative '../spec_helper'
require_relative '../../src/models/hardware'
RSpec.describe(HardwareController) do
# /hardware - redirects to /hardware/list
# GET /hardware - redirects to /hardware/list
describe 'GET /hardware' do
before { get '/hardware' }
@@ -20,7 +21,7 @@ RSpec.describe(HardwareController) do
end
end
# /hardware/list - displays a table of hardwares
# GET /hardware/list - displays a table of hardwares
describe 'GET /hardware/list' do
before { get '/hardware/list' }
@@ -37,7 +38,7 @@ RSpec.describe(HardwareController) do
end
end
# /hardware/add - form for adding hardware
# GET /hardware/add - form for adding hardware
describe 'GET /hardware/add' do
before { get '/hardware/add' }
@@ -53,4 +54,59 @@ RSpec.describe(HardwareController) do
expect(last_response.body).to(include('Add new hardware'))
end
end
# POST /hardware/add - backend for adding a hardware component
describe 'POST /hardware/add' do
before do
request_data = {
hardware_name: 'Test Hardware',
hardware_type: 'gpu',
}
post '/hardware/add', request_data
end
it 'Hardware add POST route is a redirect.' do
expect(last_response).to(be_redirect)
end
it 'Hardware add POST route is an HTML response.' do
expect(last_response['Content-Type']).to(include('text/html'))
end
it 'Hardware add POST route Location header points to /hardware/1' do
expect(last_response['Location']).to(eq("#{BASE_URL}/hardware/1"))
end
it 'Hardware add POST route creates new Hardware.' do
expect(Hardware.count).to(eq(1))
end
it 'Hardware add POST route created hardware has name.' do
expect(Hardware.first.name).to(eq('Test Hardware'))
end
it 'Hardware add POST route created hardware has type.' do
expect(Hardware.first.type).to(eq('gpu'))
end
end
# GET /hardware/:hardware_id - page for viewing a hardware model
describe 'GET /hardware/:hardware_id' do
before do
@hardware = Hardware.create(name: 'Test Hardware', type: 'gpu')
get "/hardware/#{@hardware.id}"
end
it 'Hardware view page returns 200.' do
expect(last_response).to(be_ok)
end
it 'Hardware view page is an HTML response' do
expect(last_response['Content-Type']).to(include('text/html'))
end
it 'Hardware view page contains "Add new hardware" on page.' do
expect(last_response.body).to(include("#{@hardware.name}"))
end
end
end