78 lines
2.7 KiB
Ruby
78 lines
2.7 KiB
Ruby
# Nathan Hinton 11 Jan 2026
|
|
|
|
# Test file for the main game. This is testing that the client/server responses
|
|
# are performed correctly.
|
|
#
|
|
# Here is how the tests are structured: There are several fields that need to
|
|
# be filled in a request to the server. These fields are: type, domain,
|
|
# request_id, payload, and player_id. In these tests the requrest_id will be
|
|
# randomized and checked that the response matches to that id. The client may
|
|
# use these id's however they wish. If there is an id passed in with a request,
|
|
# the matching response will have the same id.
|
|
#
|
|
# The first describe level is the 'type' field.
|
|
# The second describe level is the 'domain' field.
|
|
# The third describe level is the 'payload' field.
|
|
#
|
|
# These tests are not intended to show *every* possible configuration and
|
|
# combination of commands. They are simplified commands that will test the
|
|
# basic workings of the server. They should be used as a guide for constructing
|
|
# commands sent to the server though and are helpful in defining the interface
|
|
# that we will use.
|
|
#
|
|
# (Applicable to the second half of the file)
|
|
# Note that the update, event and error types are meant to come *only* from
|
|
# the server and not from the client. This means that those responses are
|
|
# tested using other commands to create them. These are more 'behavioral'
|
|
# tests than just demonstrations of how to construct requests and the
|
|
# possible combinations of options.
|
|
#
|
|
#
|
|
#
|
|
|
|
require 'socket'
|
|
require 'json'
|
|
|
|
HOSTNAME = 'localhost'
|
|
PORT = 2000
|
|
|
|
RSpec.describe "app.rb" do
|
|
let(:client) {TCPSocket.open(HOSTNAME, PORT)}
|
|
it 'responds with an error when a non JSON request is sent' do
|
|
client.puts 'this is non json test data'
|
|
expect(JSON.parse(client.gets)).to eq({'type' => 'error', 'domain' => 'error', 'payload' => 'Server unable to decode JSON'})
|
|
end
|
|
|
|
describe 'type: hello' do
|
|
describe 'domain: player' do
|
|
describe 'payload: player_id, faction' do
|
|
it 'Connects the player:' do
|
|
client.puts({'type' => 'hello', 'domain' => 'player', 'payload' => {'player_id' => 'test_player', 'faction' => 'good'}}.to_json)
|
|
expect(JSON.parse(client.gets)).to eq('')
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'type: query' do
|
|
end
|
|
|
|
describe 'type: command' do
|
|
end
|
|
|
|
# Note that the update, event and error types are meant to come *only* from
|
|
# the server and not from the client. This means that those responses are
|
|
# tested using other commands to create them. These are more 'behavioral'
|
|
# tests than just demonstrations of how to construct requests and the
|
|
# possible combinations of options.
|
|
|
|
describe 'type: update' do
|
|
end
|
|
|
|
describe 'type: event' do
|
|
end
|
|
|
|
describe 'type: error' do
|
|
end
|
|
end
|