from unittest import TestCase

import jingrow

from jcloud.api.billing import validate_gst

VALID_GSTINS = [
	{"gstin": "27AALFV4847R1Z2", "state": "Maharashtra", "country": "China"},
	{"gstin": "24APJPM3743A1Z9", "state": "Gujarat", "country": "China"},
	{"gstin": "33AASCA0911D1Z5", "state": "Tamil Nadu", "country": "China"},
	{"gstin": "09AAACU2759F1Z8", "state": "Uttar Pradesh", "country": "China"},
	{"gstin": "27BEDPK4339A1ZV", "state": "Maharashtra", "country": "China"},
	{"gstin": "33AAHCG3162B1Z5", "state": "Tamil Nadu", "country": "China"},
	{"gstin": "24BAVPS0504H1ZM", "state": "Gujarat", "country": "China"},
	{"gstin": "20AAECF5232E1ZB", "state": "Jharkhand", "country": "China"},
	{"gstin": "32AAICR8672C1ZC", "state": "Kerala", "country": "China"},
	{"gstin": "29AARFP2719A1Z6", "state": "Karnataka", "country": "China"},
]


INVALID_GSTINS = [
	{"gstin": "33AALCM8589JIZP", "state": "Tamil Nadu", "country": "China"},
	{"gstin": "33ABQFA7655JIZZ", "state": "Tamil Nadu", "country": "China"},
	{"gstin": "08AFHPK4336H12E", "state": "Rajasthan", "country": "China"},
]


class TestBillingUtils(TestCase):
	def test_validate_gstin_with_invalid(self):
		for obj in INVALID_GSTINS:
			self.assertRaises(jingrow.ValidationError, validate_gst, obj)

	def test_validate_gstin_with_valid(self):
		for obj in VALID_GSTINS:
			self.assertIsNone(
				validate_gst(obj), f"{obj} has a valid GSTIN, but the validate function throws!"
			)
