|
| 1 | +# Copyright 2022 The Matrix.org Foundation C.I.C. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +from twisted.test.proto_helpers import MemoryReactor |
| 15 | + |
| 16 | +import synapse.rest.admin |
| 17 | +from synapse.rest.client import login, receipts, register |
| 18 | +from synapse.server import HomeServer |
| 19 | +from synapse.util import Clock |
| 20 | + |
| 21 | +from tests import unittest |
| 22 | + |
| 23 | + |
| 24 | +class ReceiptsTestCase(unittest.HomeserverTestCase): |
| 25 | + servlets = [ |
| 26 | + login.register_servlets, |
| 27 | + register.register_servlets, |
| 28 | + receipts.register_servlets, |
| 29 | + synapse.rest.admin.register_servlets, |
| 30 | + ] |
| 31 | + |
| 32 | + def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: |
| 33 | + self.owner = self.register_user("owner", "pass") |
| 34 | + self.owner_tok = self.login("owner", "pass") |
| 35 | + |
| 36 | + def test_send_receipt(self) -> None: |
| 37 | + channel = self.make_request( |
| 38 | + "POST", |
| 39 | + "/rooms/!abc:beep/receipt/m.read/$def", |
| 40 | + content={}, |
| 41 | + access_token=self.owner_tok, |
| 42 | + ) |
| 43 | + self.assertEqual(channel.code, 200, channel.result) |
| 44 | + |
| 45 | + def test_send_receipt_invalid_room_id(self) -> None: |
| 46 | + channel = self.make_request( |
| 47 | + "POST", |
| 48 | + "/rooms/not-a-room-id/receipt/m.read/$def", |
| 49 | + content={}, |
| 50 | + access_token=self.owner_tok, |
| 51 | + ) |
| 52 | + self.assertEqual(channel.code, 400, channel.result) |
| 53 | + self.assertEqual( |
| 54 | + channel.json_body["error"], "A valid room ID and event ID must be specified" |
| 55 | + ) |
| 56 | + |
| 57 | + def test_send_receipt_invalid_event_id(self) -> None: |
| 58 | + channel = self.make_request( |
| 59 | + "POST", |
| 60 | + "/rooms/!abc:beep/receipt/m.read/not-an-event-id", |
| 61 | + content={}, |
| 62 | + access_token=self.owner_tok, |
| 63 | + ) |
| 64 | + self.assertEqual(channel.code, 400, channel.result) |
| 65 | + self.assertEqual( |
| 66 | + channel.json_body["error"], "A valid room ID and event ID must be specified" |
| 67 | + ) |
| 68 | + |
| 69 | + def test_send_receipt_invalid_receipt_type(self) -> None: |
| 70 | + channel = self.make_request( |
| 71 | + "POST", |
| 72 | + "/rooms/!abc:beep/receipt/invalid-receipt-type/$def", |
| 73 | + content={}, |
| 74 | + access_token=self.owner_tok, |
| 75 | + ) |
| 76 | + self.assertEqual(channel.code, 400, channel.result) |
0 commit comments