2016-01-10 11:12:38 +00:00
|
|
|
defmodule ISNTest do
|
2015-05-21 06:46:07 +00:00
|
|
|
use ExUnit.Case, async: true
|
2016-01-10 11:12:38 +00:00
|
|
|
import ISN.TestHelper
|
2016-07-17 09:14:41 +00:00
|
|
|
alias Postgrex, as: P
|
2015-05-21 06:46:07 +00:00
|
|
|
|
|
|
|
|
setup do
|
2016-01-10 11:12:38 +00:00
|
|
|
options = Keyword.merge(conn_options, [extensions: [{ISN, {}}]])
|
2015-06-18 15:26:42 +00:00
|
|
|
{:ok, pid} = P.start_link(options)
|
2015-05-21 06:46:07 +00:00
|
|
|
{:ok, [pid: pid]}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "encode and decode isbn", context do
|
2015-08-10 19:57:49 +00:00
|
|
|
assert [["1-937785-58-0"]] =
|
2015-05-21 06:46:07 +00:00
|
|
|
query(context[:pid], "SELECT $1::isbn", ['1937785580'])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "encode and decode isbn13", context do
|
2015-08-10 19:57:49 +00:00
|
|
|
assert [["978-1-937785-58-1"]] =
|
2015-05-21 06:46:07 +00:00
|
|
|
query(context[:pid], "SELECT $1::isbn13", ['9781937785581'])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "encode and decode ismn", context do
|
2015-08-10 19:57:49 +00:00
|
|
|
assert [["M-060-11561-5"]] =
|
2015-05-21 06:46:07 +00:00
|
|
|
query(context[:pid], "SELECT $1::ismn", ['9790060115615'])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "encode and decode ismn13", context do
|
2015-08-10 19:57:49 +00:00
|
|
|
assert [["979-0-060-11561-5"]] =
|
2015-05-21 06:46:07 +00:00
|
|
|
query(context[:pid], "SELECT $1::ismn13", ['9790060115615'])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "encode and decode issn", context do
|
2015-08-10 19:57:49 +00:00
|
|
|
assert [["1436-4522"]] =
|
2015-05-21 06:46:07 +00:00
|
|
|
query(context[:pid], "SELECT $1::issn", ['14364522'])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "encode and decode issn13", context do
|
2015-08-10 19:57:49 +00:00
|
|
|
assert [["977-1436-452-00-8"]] =
|
2015-05-21 06:46:07 +00:00
|
|
|
query(context[:pid], "SELECT issn13(issn('1436-4522'))", [])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "encode and decode ean13", context do
|
2015-08-10 19:57:49 +00:00
|
|
|
assert [["022-035648348-1"]] =
|
2015-05-21 06:46:07 +00:00
|
|
|
query(context[:pid], "SELECT $1::ean13", ["0220356483481"])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "encode and decode upc", context do
|
2015-08-10 19:57:49 +00:00
|
|
|
assert [["220356483481"]] =
|
2015-05-21 06:46:07 +00:00
|
|
|
query(context[:pid], "SELECT $1::upc", ["220356483481"])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|