forked from mtusi2026/mtusi2026lab2
feat: lab2 done
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
meta {
|
||||
name: History first page
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseUrl}}/api/v1/chats/{{chatId}}/messages?limit=1
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer {{secondToken}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Keyset-пагинация по (created_at, id) по возрастанию. История читается
|
||||
любой действующей сессией участника — здесь второй сессией, что заодно
|
||||
показывает read-after-write для ранее отправленного сообщения.
|
||||
Сохраняет nextCursor.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("200 ok", function() {
|
||||
expect(res.status).to.equal(200);
|
||||
});
|
||||
|
||||
test("страница ограничена limit", function() {
|
||||
expect(res.body.items.length).to.equal(1);
|
||||
});
|
||||
|
||||
test("есть курсор на следующую страницу", function() {
|
||||
expect(res.body.next_cursor).to.be.a("string");
|
||||
});
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar("nextCursor", res.body.next_cursor);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
meta {
|
||||
name: History next page by cursor
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseUrl}}/api/v1/chats/{{chatId}}/messages?limit=1&cursor={{nextCursor}}
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer {{secondToken}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Продолжение по курсору. Курсор привязан к чату: значение от другого
|
||||
чата вернёт 400. Последний элемент предыдущей страницы не повторяется.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("200 ok", function() {
|
||||
expect(res.status).to.equal(200);
|
||||
});
|
||||
|
||||
test("второй элемент не дублирует первый", function() {
|
||||
expect(res.body.items.length).to.equal(1);
|
||||
expect(res.body.items[0].id).to.not.equal(bru.getVar("messageId"));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
meta {
|
||||
name: Send message as second user
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/chats/{{chatId}}/messages
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer {{secondToken}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Любой участник чата может писать. Второе сообщение нужно, чтобы
|
||||
страница с limit=1 вернула next_cursor и пагинацию можно было проверить.
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"text": "Ответ второго участника"
|
||||
}
|
||||
}
|
||||
|
||||
tests {
|
||||
test("201 created", function() {
|
||||
expect(res.status).to.equal(201);
|
||||
});
|
||||
|
||||
test("sender — второй пользователь", function() {
|
||||
expect(res.body.sender_id).to.equal(bru.getVar("secondUserId"));
|
||||
});
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar("secondMessageId", res.body.id);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
meta {
|
||||
name: Send message
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/chats/{{chatId}}/messages
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer {{token}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Отправитель берётся из Bearer-идентичности; поле sender_id в теле
|
||||
не принимается (лишние поля — 400). Пустой или пробельный текст — 400.
|
||||
Запись коммитит сообщение и увеличивает chats.message_version в одной
|
||||
транзакции. Сохраняет messageId.
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"text": "Привет из Bruno 👋"
|
||||
}
|
||||
}
|
||||
|
||||
tests {
|
||||
test("201 created", function() {
|
||||
expect(res.status).to.equal(201);
|
||||
});
|
||||
|
||||
test("sender выведен из сессии", function() {
|
||||
expect(res.body.sender_id).to.equal(bru.getVar("userId"));
|
||||
});
|
||||
|
||||
test("сообщение в нужном чате", function() {
|
||||
expect(res.body.chat_id).to.equal(bru.getVar("chatId"));
|
||||
});
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar("messageId", res.body.id);
|
||||
}
|
||||
Reference in New Issue
Block a user