"""Static monthly schema contract, not a live install or API acceptance test.""" import json import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[1] L2 = ROOT / "packs/Salesforce-PingCAP-L2" FINAL = ROOT / "packs/NOT-EDIT-final-merged-packs" API = "NetSuite_Revenue_Monthly__c" def load(path): return json.loads(path.read_text(encoding="utf-8")) class NetSuiteMonthlyObjectContractTest(unittest.TestCase): def setUp(self): payload = load(L2 / "objects" / f"{API}.json") self.assertEqual(len(payload), 1) self.obj = payload[0] self.fields = {field["apiName"]: field for field in self.obj["fields"]} def test_registered_source_and_exact_final_projection(self): matches = [c for c in load(L2 / "pack.json")["components"] if c.get("businessKey") == f"object:{API}"] self.assertEqual(matches, [{"kind": "object_spec", "businessKey": f"object:{API}", "manageability": "locked", "path": f"objects/{API}.json"}]) self.assertEqual([o for o in load(FINAL / "objects/standard_objects_spec.json") if o.get("apiName") == API], [self.obj]) def test_exact_fields_and_required_contract(self): expected = { "Name": "string", "CRM_Account__c": "reference", "Revenue_Month__c": "date", "Product_Name__c": "picklist", "Product_Category__c": "picklist", "Company__c": "string", "Transaction_Currency__c": "string", "Transaction_Amount__c": "currency", "Base_Amount__c": "currency", "NetSuite_Posting_Period_Id__c": "string", "Monthly_Revenue_Key__c": "string", "Sync_Run_Id__c": "string", "Snapshot_Row_Key__c": "string", "Source_Line_Count__c": "double", "Source_Payload_Set_Hash__c": "string", "Payload_Hash__c": "string", } self.assertEqual(len(self.obj["fields"]), len(expected)) handoff = (ROOT / "docs/netsuite-revenue-monthly-object.md").read_text(encoding="utf-8") self.assertIn(f"{len(expected)} authored fields including `Name`", handoff) self.assertEqual({k: v["type"] for k, v in self.fields.items()}, expected) self.assertEqual({k for k, v in self.fields.items() if v.get("required")}, set(expected) - {"Base_Amount__c"}) self.assertTrue(self.fields["Name"]["isNameField"]) for field in self.fields.values(): self.assertNotIn("formula", field) self.assertNotIn("default", field) self.assertIsNot(field.get("createable"), False) self.assertIsNot(field.get("updateable"), False) def test_account_lookup_and_private_sharing(self): field = self.fields["CRM_Account__c"] self.assertEqual(field["referenceTo"], ["Account"]) self.assertEqual(field["relationshipName"], "CRM_Account__r") self.assertEqual(field["childRelationshipName"], "NetSuite_Monthly_Revenues") self.assertEqual(field["deleteConstraint"], "Restrict") self.assertEqual(self.obj["sharingModel"], "Private") self.assertFalse(self.obj["enableHierarchySharing"]) self.assertEqual(self.obj["tableType"], "custom_object") def test_snapshot_only_unique_identity_and_hash_shape(self): self.assertEqual({k for k, f in self.fields.items() if f.get("unique")}, {"Snapshot_Row_Key__c"}) for key in ("Monthly_Revenue_Key__c", "Snapshot_Row_Key__c", "Source_Payload_Set_Hash__c", "Payload_Hash__c"): field = self.fields[key] self.assertEqual((field["minLength"], field["maxLength"]), (64, 64)) self.assertEqual(field["regex"], "^[0-9a-f]{64}$") def test_product_catalog_preserves_normalization(self): products = {o["value"] for o in self.fields["Product_Name__c"]["options"]} self.assertEqual(products, {"Dedicated", "Starter", "Essential", "Premium", "Lake", "BYOC", "Support Plan", "Subscription", "Professional Service"}) self.assertEqual({o["value"] for o in self.fields["Product_Category__c"]["options"]}, {"Cloud", "OP"}) def test_signed_amounts_no_fx_or_usd_default(self): for name in ("Transaction_Amount__c", "Base_Amount__c"): field = self.fields[name] self.assertNotIn("minValue", field) self.assertNotIn("default", field) currency = self.fields["Transaction_Currency__c"] self.assertEqual(currency["regex"], "^[A-Z]{3}$") self.assertNotIn("options", currency) self.assertNotIn("default", currency) self.assertEqual(self.fields["Source_Line_Count__c"]["minValue"], 1) def test_prefix_unique_in_l2_and_final(self): objects = [] for path in (L2 / "objects").glob("*.json"): payload = load(path) objects.extend(payload if isinstance(payload, list) else [payload]) for specs in (objects, load(FINAL / "objects/standard_objects_spec.json")): self.assertEqual([o["apiName"] for o in specs if o.get("keyPrefix") == "a2Z"], [API]) def test_prefix_does_not_reuse_salesforce_migration_identity(self): snapshot = load(ROOT / "docs/migration/attachments/salesforce_describe_objects_2026-05-17.json") owners = {obj["keyPrefix"].strip().lower(): obj["name"] for obj in snapshot["sobjects"] if obj.get("keyPrefix")} # Regression: L2/final uniqueness alone missed a migrated managed object. self.assertEqual(owners["a1y"], "awsapn__Field_Mapping_Detail__c") self.assertNotIn(self.obj["keyPrefix"].strip().lower(), owners) def test_indices_reference_declared_columns_without_unique_monthly_key(self): self.assertEqual(self.obj["indices"], [ {"name": "idx_nrm_account_month", "columns": ["CRM_Account__c", "Revenue_Month__c"]}, {"name": "idx_nrm_month_run", "columns": ["Revenue_Month__c", "Sync_Run_Id__c"]}, {"name": "idx_nrm_monthly_key", "columns": ["Monthly_Revenue_Key__c"]}, ]) for index in self.obj["indices"]: self.assertTrue(set(index["columns"]) <= self.fields.keys()) self.assertFalse(index.get("unique", False)) if __name__ == "__main__": unittest.main()