@@ -54,7 +54,7 @@ def test_code_format(self, tmp_path):
5454 with patch ("gateway.pairing.PAIRING_DIR" , tmp_path ):
5555 store = PairingStore ()
5656 code = store .generate_code ("telegram" , "user1" , "Alice" )
57- assert code is not None
57+ assert isinstance ( code , str ) and len ( code ) == CODE_LENGTH
5858 assert len (code ) == CODE_LENGTH
5959 assert all (c in ALPHABET for c in code )
6060
@@ -65,7 +65,7 @@ def test_code_uniqueness(self, tmp_path):
6565 codes = set ()
6666 for i in range (3 ):
6767 code = store .generate_code ("telegram" , f"user{ i } " )
68- assert code is not None
68+ assert isinstance ( code , str ) and len ( code ) == CODE_LENGTH
6969 codes .add (code )
7070 assert len (codes ) == 3
7171
@@ -91,30 +91,31 @@ def test_same_user_rate_limited(self, tmp_path):
9191 store = PairingStore ()
9292 code1 = store .generate_code ("telegram" , "user1" )
9393 code2 = store .generate_code ("telegram" , "user1" )
94- assert code1 is not None
94+ assert isinstance ( code1 , str ) and len ( code1 ) == CODE_LENGTH
9595 assert code2 is None # rate limited
9696
9797 def test_different_users_not_rate_limited (self , tmp_path ):
9898 with patch ("gateway.pairing.PAIRING_DIR" , tmp_path ):
9999 store = PairingStore ()
100100 code1 = store .generate_code ("telegram" , "user1" )
101101 code2 = store .generate_code ("telegram" , "user2" )
102- assert code1 is not None
103- assert code2 is not None
102+ assert isinstance ( code1 , str ) and len ( code1 ) == CODE_LENGTH
103+ assert isinstance ( code2 , str ) and len ( code2 ) == CODE_LENGTH
104104
105105 def test_rate_limit_expires (self , tmp_path ):
106106 with patch ("gateway.pairing.PAIRING_DIR" , tmp_path ):
107107 store = PairingStore ()
108108 code1 = store .generate_code ("telegram" , "user1" )
109- assert code1 is not None
109+ assert isinstance ( code1 , str ) and len ( code1 ) == CODE_LENGTH
110110
111111 # Simulate rate limit expiry
112112 limits = store ._load_json (store ._rate_limit_path ())
113113 limits ["telegram:user1" ] = time .time () - RATE_LIMIT_SECONDS - 1
114114 store ._save_json (store ._rate_limit_path (), limits )
115115
116116 code2 = store .generate_code ("telegram" , "user1" )
117- assert code2 is not None
117+ assert isinstance (code2 , str ) and len (code2 ) == CODE_LENGTH
118+ assert code2 != code1
118119
119120
120121# ---------------------------------------------------------------------------
@@ -132,7 +133,7 @@ def test_max_pending_per_platform(self, tmp_path):
132133 codes .append (code )
133134
134135 # First MAX_PENDING_PER_PLATFORM should succeed
135- assert all (c is not None for c in codes [:MAX_PENDING_PER_PLATFORM ])
136+ assert all (isinstance ( c , str ) and len ( c ) == CODE_LENGTH for c in codes [:MAX_PENDING_PER_PLATFORM ])
136137 # Next one should be blocked
137138 assert codes [MAX_PENDING_PER_PLATFORM ] is None
138139
@@ -143,7 +144,7 @@ def test_different_platforms_independent(self, tmp_path):
143144 store .generate_code ("telegram" , f"user{ i } " )
144145 # Different platform should still work
145146 code = store .generate_code ("discord" , "user0" )
146- assert code is not None
147+ assert isinstance ( code , str ) and len ( code ) == CODE_LENGTH
147148
148149
149150# ---------------------------------------------------------------------------
@@ -158,7 +159,9 @@ def test_approve_valid_code(self, tmp_path):
158159 code = store .generate_code ("telegram" , "user1" , "Alice" )
159160 result = store .approve_code ("telegram" , code )
160161
161- assert result is not None
162+ assert isinstance (result , dict )
163+ assert "user_id" in result
164+ assert "user_name" in result
162165 assert result ["user_id" ] == "user1"
163166 assert result ["user_name" ] == "Alice"
164167
@@ -187,14 +190,18 @@ def test_approve_case_insensitive(self, tmp_path):
187190 store = PairingStore ()
188191 code = store .generate_code ("telegram" , "user1" , "Alice" )
189192 result = store .approve_code ("telegram" , code .lower ())
190- assert result is not None
193+ assert isinstance (result , dict )
194+ assert result ["user_id" ] == "user1"
195+ assert result ["user_name" ] == "Alice"
191196
192197 def test_approve_strips_whitespace (self , tmp_path ):
193198 with patch ("gateway.pairing.PAIRING_DIR" , tmp_path ):
194199 store = PairingStore ()
195200 code = store .generate_code ("telegram" , "user1" , "Alice" )
196201 result = store .approve_code ("telegram" , f" { code } " )
197- assert result is not None
202+ assert isinstance (result , dict )
203+ assert result ["user_id" ] == "user1"
204+ assert result ["user_name" ] == "Alice"
198205
199206 def test_invalid_code_returns_none (self , tmp_path ):
200207 with patch ("gateway.pairing.PAIRING_DIR" , tmp_path ):
0 commit comments