-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathend2end_pg.rb
executable file
·70 lines (65 loc) · 2.22 KB
/
end2end_pg.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
gem 'minitest' # ensures using the gem, and not the built-in MT
require 'minitest/autorun'
require_relative '../examples/pg/query_sql'
class TestPg < Minitest::Test
def setup
pg_params = {
'dbname' => ENV['DB_NAME'],
'host' => ENV['POSTGRES_HOST'],
'user' => ENV['DB_USER'],
'password' => ENV['DB_PASS']
}
@query_sql = PgCodegen::QuerySql.new({ }, pg_params)
end
def test_flow
first_inserted_id = create_first_author_and_assert
create_second_author_and_assert
delete_author_and_assert(first_inserted_id)
end
def create_first_author_and_assert
create_author_args = PgCodegen::CreateAuthorArgs.new(
name: Consts::BOJACK_AUTHOR,
bio: Consts::BOJACK_THEME
)
@query_sql.create_author(create_author_args)
inserted_id = 1
get_author_args = PgCodegen::GetAuthorArgs.new(id: inserted_id)
actual = @query_sql.get_author(get_author_args)
expected = PgCodegen::GetAuthorRow.new(
id: 1,
name: Consts::BOJACK_AUTHOR,
bio: Consts::BOJACK_THEME
)
assert_equal(expected, actual)
inserted_id
end
def create_second_author_and_assert
create_author_args = PgCodegen::CreateAuthorArgs.new(
name: Consts::DR_SEUSS_AUTHOR,
bio: Consts::DR_SEUSS_QUOTE
)
@query_sql.create_author(create_author_args)
get_author_args = PgCodegen::GetAuthorArgs.new(id: 2)
actual = @query_sql.get_author(get_author_args)
expected = PgCodegen::GetAuthorRow.new(
id: 2,
name: Consts::DR_SEUSS_AUTHOR,
bio: Consts::DR_SEUSS_QUOTE
)
assert_equal(expected, actual)
end
def delete_author_and_assert(id_to_delete)
delete_author_args = PgCodegen::DeleteAuthorArgs.new(id: id_to_delete)
@query_sql.delete_author(delete_author_args)
actual = @query_sql.list_authors
expected = [
PgCodegen::ListAuthorsRow.new(
id: 2,
name: Consts::DR_SEUSS_AUTHOR,
bio: Consts::DR_SEUSS_QUOTE
)
]
assert_equal(expected, actual)
end
end