diff --git a/tests/test_apple_console.py b/tests/test_apple_console.py index ae4d630..ed10790 100644 --- a/tests/test_apple_console.py +++ b/tests/test_apple_console.py @@ -74,5 +74,36 @@ def test_invalid_purposes_report_options_without_running_iris(self): run.assert_not_called() +class SetAvailabilityTests(unittest.TestCase): + def call_with_plan(self, territories, available_in_new): + response = {"available": ["BRA", "USA"]} + with patch.object(apple_console, "_run_iris", return_value=response) as run: + result = apple_console.set_availability("test-app", territories, available_in_new) + run.assert_called_once() + app_id, body = run.call_args.args + self.assertEqual(app_id, "test-app") + self.assertIs(result, response) + match = re.search(r"const want=(.*);", body) + self.assertIsNotNone(match) + self.assertIn("id:'test-app'", body) + self.assertIn("/iris/v2/appAvailabilities/test-app/territoryAvailabilities?", body) + return json.loads(match.group(1)), body + + def test_normalizes_deduplicates_and_sorts_territories(self): + wanted, _ = self.call_with_plan(["usa", "BRA", "bra"], False) + self.assertEqual(wanted, ["BRA", "USA"]) + + def test_serializes_both_new_territory_options(self): + for available_in_new, expected in [(True, "true"), (False, "false")]: + with self.subTest(available_in_new=available_in_new): + _, body = self.call_with_plan(["USA"], available_in_new) + self.assertIn(f"availableInNewTerritories:{expected}", body) + self.assertNotIn(f"availableInNewTerritories:{available_in_new}", body) + + def test_empty_territories_are_preserved(self): + wanted, _ = self.call_with_plan([], False) + self.assertEqual(wanted, []) + + if __name__ == "__main__": unittest.main()