Skip to content

Commit 99cc41d

Browse files
committed
chore: tests for list type
1 parent ebae7b8 commit 99cc41d

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

tests/src/main/resources/postgres/queries.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SELECT * FROM users;
1010
-- name: GetMessage :one
1111
SELECT * FROM messages WHERE message_id = $1;
1212

13-
-- name: CreateMessage :exec
13+
-- name: CreateMessage :one
1414
INSERT INTO messages(chat_id, user_id, content, attachments)
15-
VALUES ($1, $2, $3, $4);
15+
VALUES ($1, $2, $3, $4)
16+
RETURNING message_id;

tests/src/main/resources/postgres/schema.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CREATE TABLE users (
99
-- Tokens table
1010
CREATE TABLE tokens (
1111
token_id SERIAL PRIMARY KEY,
12-
user_id UUID NOT NULL REFERENCES users(user_id),
12+
user_id UUID NOT NULL,
1313
token VARCHAR(255) UNIQUE NOT NULL,
1414
expiry TIMESTAMP NOT NULL
1515
);
@@ -24,8 +24,8 @@ CREATE TABLE chats (
2424
-- Messages table with array column for attachments
2525
CREATE TABLE messages (
2626
message_id SERIAL PRIMARY KEY,
27-
chat_id INTEGER NOT NULL REFERENCES chats(chat_id),
28-
user_id UUID NOT NULL REFERENCES users(user_id),
27+
chat_id INTEGER NOT NULL,
28+
user_id UUID NOT NULL,
2929
content TEXT NOT NULL,
3030
attachments TEXT[], -- Array column for storing attachment URLs
3131
sent_at_time TIME DEFAULT NOW()::time without time zone,

tests/src/test/java/io/github/tandemdude/sgj/postgres/TestQueries.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.sql.Connection;
1010
import java.sql.DriverManager;
1111
import java.sql.SQLException;
12+
import java.util.List;
1213
import java.util.UUID;
1314

1415
import static org.assertj.core.api.Assertions.assertThat;
@@ -76,4 +77,19 @@ public void listUsersReturnsPopulatedListRecordsFound() throws Exception {
7677
assertThat(found.size()).isEqualTo(2);
7778
}
7879
}
80+
81+
@Test
82+
@DisplayName("CreateMessage processes input list correctly")
83+
public void createMessageProcessesInputListCorrectly() throws Exception {
84+
try (var conn = getConn()) {
85+
var q = new Queries(conn);
86+
87+
var created = q.createMessage(1, UUID.randomUUID(), "foo", List.of("bar", "baz", "bork"));
88+
assertThat(created).isPresent();
89+
90+
var found = q.getMessage(created.get().message_id());
91+
assertThat(found).isPresent();
92+
assertThat(found.get().attachments()).containsExactly("bar", "baz", "bork");
93+
}
94+
}
7995
}

0 commit comments

Comments
 (0)