diff --git a/src/openklant/components/klantinteracties/api/tests/test_partijen.py b/src/openklant/components/klantinteracties/api/tests/test_partijen.py index 2d486409..9e8cbf7d 100644 --- a/src/openklant/components/klantinteracties/api/tests/test_partijen.py +++ b/src/openklant/components/klantinteracties/api/tests/test_partijen.py @@ -2022,6 +2022,139 @@ def test_destroy_partij_identificator(self): data = response.json() self.assertEqual(data["count"], 0) + def test_invalid_choice_partij_identificator_code_register(self): + url = reverse("klantinteracties:partijidentificator-list") + partij = PartijFactory.create() + data = { + "identificeerdePartij": {"uuid": str(partij.uuid)}, + "anderePartijIdentificator": "anderePartijIdentificator", + "partijIdentificator": { + "codeObjecttype": "natuurlijk_persoon", + "codeSoortObjectId": "bsn", + "objectId": "123456789", + "codeRegister": "test", + }, + } + response = self.client.post(url, data) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data["code"], "invalid") + self.assertEqual(response.data["title"], "Invalid input.") + self.assertEqual( + response.data["invalid_params"][0]["name"], + "partijIdentificator.codeRegister", + ) + self.assertEqual(response.data["invalid_params"][0]["code"], "invalid_choice") + self.assertEqual( + response.data["invalid_params"][0]["reason"], + '"test" is een ongeldige keuze.', + ) + + def test_invalid_choice_partij_identificator_code_objecttype(self): + url = reverse("klantinteracties:partijidentificator-list") + partij = PartijFactory.create() + data = { + "identificeerdePartij": {"uuid": str(partij.uuid)}, + "anderePartijIdentificator": "anderePartijIdentificator", + "partijIdentificator": { + "codeObjecttype": "test", + "codeSoortObjectId": "bsn", + "objectId": "123456789", + "codeRegister": "brp", + }, + } + response = self.client.post(url, data) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data["code"], "invalid") + self.assertEqual(response.data["title"], "Invalid input.") + self.assertEqual( + response.data["invalid_params"][0]["name"], + "partijIdentificator.codeObjecttype", + ) + self.assertEqual(response.data["invalid_params"][0]["code"], "invalid_choice") + self.assertEqual( + response.data["invalid_params"][0]["reason"], + '"test" is een ongeldige keuze.', + ) + + def test_invalid_choice_partij_identificator_code_soort_object_id(self): + url = reverse("klantinteracties:partijidentificator-list") + partij = PartijFactory.create() + data = { + "identificeerdePartij": {"uuid": str(partij.uuid)}, + "anderePartijIdentificator": "anderePartijIdentificator", + "partijIdentificator": { + "codeObjecttype": "natuurlijk_persoon", + "codeSoortObjectId": "test", + "objectId": "123456789", + "codeRegister": "brp", + }, + } + response = self.client.post(url, data) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data["code"], "invalid") + self.assertEqual(response.data["title"], "Invalid input.") + self.assertEqual( + response.data["invalid_params"][0]["name"], + "partijIdentificator.codeSoortObjectId", + ) + self.assertEqual(response.data["invalid_params"][0]["code"], "invalid_choice") + self.assertEqual( + response.data["invalid_params"][0]["reason"], + '"test" is een ongeldige keuze.', + ) + + def test_invalid_validation_partij_identificator_code_objecttype(self): + url = reverse("klantinteracties:partijidentificator-list") + partij = PartijFactory.create() + data = { + "identificeerdePartij": {"uuid": str(partij.uuid)}, + "anderePartijIdentificator": "anderePartijIdentificator", + "partijIdentificator": { + "codeObjecttype": "niet_natuurlijk_persoon", + "codeSoortObjectId": "bsn", + "objectId": "123456789", + "codeRegister": "brp", + }, + } + + # ValidationError, "ObjectType keuzes zijn beperkt op basis van CodeRegister." + with self.assertRaises(ValidationError): + self.client.post(url, data) + + def test_invalid_validation_partij_identificator_code_soort_object_id(self): + url = reverse("klantinteracties:partijidentificator-list") + partij = PartijFactory.create() + data = { + "identificeerdePartij": {"uuid": str(partij.uuid)}, + "anderePartijIdentificator": "anderePartijIdentificator", + "partijIdentificator": { + "codeObjecttype": "natuurlijk_persoon", + "codeSoortObjectId": "kvk_nummer", + "objectId": "123456789", + "codeRegister": "brp", + }, + } + # "CodeSoortObjectId keuzes zijn beperkt op basis van CodeObjectType.", + with self.assertRaises(ValidationError): + self.client.post(url, data) + + def test_invalid_validation_partij_identificator_object_id(self): + url = reverse("klantinteracties:partijidentificator-list") + partij = PartijFactory.create() + data = { + "identificeerdePartij": {"uuid": str(partij.uuid)}, + "anderePartijIdentificator": "anderePartijIdentificator", + "partijIdentificator": { + "codeObjecttype": "natuurlijk_persoon", + "codeSoortObjectId": "bsn", + "objectId": "12", + "codeRegister": "brp", + }, + } + # "De lengte van de ObjectId moet tussen 8 en 9 liggen." + with self.assertRaises(ValidationError): + self.client.post(url, data) + def test_valid_validation_partij_identificator(self): # All validations pass url = reverse("klantinteracties:partijidentificator-list")