# frozen_string_literal: true
require "test_helper"
+
require "book"
+require "store_mock"
class BookTest < Minitest::Test
def test_that_it_can_handle_epub_and_pdf_files
assert_equal expected, Book.grouping_for_title(input)
end
end
+
+ def test_load_from_file
+ store = StoreMock.new
+ store.expects(:get_series).returns(mock_series_LW)
+ store.connect
+ book = Book.new(store)
+
+ book.load_from_file!(File.join(TestHelper::SAMPLE_DATA_PATH, "LouisaAlcott", "LW01_Little_Women.epub"))
+
+ author = book.author
+
+ assert_equal "LouisaAlcott", author.grouping
+ assert_equal "Louisa May Alcott", author.reading_order
+ assert_equal "Alcott, Louisa May", author.sort_order
+
+ assert_equal "This story follows the lives of the four March sisters&emdash;Meg, Jo, Beth, and Amy&emdash;and details their coming of age.", book.description
+ assert_equal "en", book.language
+ assert_equal "Little Women: Or, Meg, Jo, Beth and Amy", book.title
+ assert_equal mock_series_LW.to_s, book.series_id.to_s
+ assert_equal 1, book.volume.to_i
+ end
+
+ def test_heading
+ store = StoreMock.new
+ store.expects(:get_series).returns(mock_series_LW)
+ store.connect
+ book = Book.new(store)
+
+ book.load_from_file!(File.join(TestHelper::SAMPLE_DATA_PATH, "LouisaAlcott", "LW01_Little_Women.epub"))
+
+ expected = "<b>Little Women: Or, Meg, Jo, Beth and Amy</b><br/><i>by Louisa May Alcott</i><br/>01"
+ actual = book.heading
+
+ assert_equal expected, actual
+ end
+
+ private
+
+ def mock_series_LW
+ id = 1
+ series = Series.new(id)
+ series.age = "ya"
+ series.genre = "romance"
+ series.grouping = "LoisaAlcott"
+ series.code = "LW"
+ series.descr = "Little Women"
+
+ series
+ end
end
--- /dev/null
+# frozen_string_literal: true
+
+class ConnMock
+ def initialize
+ @mock_connected = true
+ @stmts = []
+ end
+
+ def close
+ raise ".close() called on already closed connection" unless @mock_connected
+
+ @mock_connected = false
+ end
+
+ def exec(*args, &block)
+ @stmts << args
+ return nil
+ end
+
+ def exec_params(*args, &block)
+ @stmts << args
+ return nil
+ end
+end