Skip to content

Commit

Permalink
Merge pull request #2776 from nextcloud/test/nextcloud/spreed-message…
Browse files Browse the repository at this point in the history
…-expiration
  • Loading branch information
provokateurin authored Jan 29, 2025
2 parents a0e10f7 + 6925096 commit 43a5c59
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
58 changes: 58 additions & 0 deletions packages/nextcloud/test/api/spreed/spreed_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,36 @@ void main() {
});
});
});

test('Message expiration', () async {
const expiration = 1;

final room = await createTestRoom();
expect(room.lastMessage.baseMessage, isNotNull);
expect(room.lastMessage.builtListNever, isNull);
expect(room.lastMessage.chatMessage, isNotNull);

await tester.client.spreed.room.setMessageExpiration(
token: room.token,
$body: spreed.RoomSetMessageExpirationRequestApplicationJson(
(b) => b.seconds = expiration,
),
);

final clearHistoryResponse = await tester.client.spreed.chat.clearHistory(
token: room.token,
);
expect(clearHistoryResponse.body.ocs.data.expirationTimestamp, isPositive);

await Future<void>.delayed(const Duration(seconds: expiration));

final getRoomResponse = await tester.client.spreed.room.getSingleRoom(
token: room.token,
);
expect(getRoomResponse.body.ocs.data.lastMessage.baseMessage, isNull);
expect(getRoomResponse.body.ocs.data.lastMessage.builtListNever, isNotNull);
expect(getRoomResponse.body.ocs.data.lastMessage.chatMessage, isNull);
});
});

group('Avatar', () {
Expand Down Expand Up @@ -463,6 +493,34 @@ void main() {
expect(response.body.ocs.data.parent!.chatMessage!.messageType, spreed.MessageType.commentDeleted);
expect(response.body.ocs.data.parent!.chatMessage!.systemMessage, '');
});

test('Clear history', () async {
final room = await createTestRoom();

final clearHistoryResponse = await tester.client.spreed.chat.clearHistory(
token: room.token,
);
expect(clearHistoryResponse.body.ocs.data.id, isPositive);
expect(clearHistoryResponse.body.ocs.data.actorType, spreed.ActorType.users);
expect(clearHistoryResponse.body.ocs.data.actorId, 'user1');
expect(clearHistoryResponse.body.ocs.data.actorDisplayName, 'User One');
expect(clearHistoryResponse.body.ocs.data.message, 'You cleared the history of the conversation');
expect(clearHistoryResponse.body.ocs.data.messageType, spreed.MessageType.system);
expect(clearHistoryResponse.body.ocs.data.systemMessage, 'history_cleared');

final receiveMessagesResponse = await tester.client.spreed.chat.receiveMessages(
token: room.token,
lookIntoFuture: spreed.ChatReceiveMessagesLookIntoFuture.$0,
);
expect(receiveMessagesResponse.body.ocs.data, hasLength(1));
expect(receiveMessagesResponse.body.ocs.data[0].id, isPositive);
expect(receiveMessagesResponse.body.ocs.data[0].actorType, spreed.ActorType.users);
expect(receiveMessagesResponse.body.ocs.data[0].actorId, 'user1');
expect(receiveMessagesResponse.body.ocs.data[0].actorDisplayName, 'User One');
expect(receiveMessagesResponse.body.ocs.data[0].message, 'You cleared the history of the conversation');
expect(receiveMessagesResponse.body.ocs.data[0].messageType, spreed.MessageType.system);
expect(receiveMessagesResponse.body.ocs.data[0].systemMessage, 'history_cleared');
});
});

group('Call', () {
Expand Down
14 changes: 14 additions & 0 deletions packages/nextcloud/test/fixtures/spreed/chat/clear_history.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
POST http://localhost/ocs/v2\.php/apps/spreed/api/v4/room
accept: application/json
authorization: Bearer mock
content-type: application/json; charset=utf-8
ocs-apirequest: true
\{"roomType":3,"invite":"","roomName":"Test","source":"","objectType":"","objectId":""\}
DELETE http://localhost/ocs/v2\.php/apps/spreed/api/v1/chat/[a-z0-9]{8}
accept: application/json
authorization: Bearer mock
ocs-apirequest: true
GET http://localhost/ocs/v2\.php/apps/spreed/api/v1/chat/[a-z0-9]{8}\?lookIntoFuture=0&limit=100&lastKnownMessageId=0&lastCommonReadId=0&timeout=30&setReadMarker=1&includeLastKnown=0&noStatusUpdate=0&markNotificationsAsRead=1
accept: application/json
authorization: Bearer mock
ocs-apirequest: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
POST http://localhost/ocs/v2\.php/apps/spreed/api/v4/room
accept: application/json
authorization: Bearer mock
content-type: application/json; charset=utf-8
ocs-apirequest: true
\{"roomType":3,"invite":"","roomName":"Test","source":"","objectType":"","objectId":""\}
POST http://localhost/ocs/v2\.php/apps/spreed/api/v4/room/[a-z0-9]{8}/message-expiration
accept: application/json
authorization: Bearer mock
content-type: application/json; charset=utf-8
ocs-apirequest: true
\{"seconds":1\}
DELETE http://localhost/ocs/v2\.php/apps/spreed/api/v1/chat/[a-z0-9]{8}
accept: application/json
authorization: Bearer mock
ocs-apirequest: true
GET http://localhost/ocs/v2\.php/apps/spreed/api/v4/room/[a-z0-9]{8}
accept: application/json
authorization: Bearer mock
ocs-apirequest: true

0 comments on commit 43a5c59

Please sign in to comment.