A social knowledge tool for researchers built on ATProto
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: add test cases for URL card creation scenarios

Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>

+74
+74
src/modules/cards/tests/application/AddUrlToLibraryUseCase.test.ts
··· 188 188 ); 189 189 expect(urlCards).toHaveLength(1); // Only one URL card 190 190 }); 191 + 192 + it('should create new URL card when another user has URL card with same URL', async () => { 193 + const url = 'https://example.com/shared'; 194 + const otherCuratorId = CuratorId.create('did:plc:othercurator').unwrap(); 195 + 196 + // First user creates URL card 197 + const firstRequest = { 198 + url, 199 + curatorId: otherCuratorId.value, 200 + }; 201 + 202 + const firstResult = await useCase.execute(firstRequest); 203 + expect(firstResult.isOk()).toBe(true); 204 + const firstResponse = firstResult.unwrap(); 205 + 206 + // Second user (different curator) should create their own URL card 207 + const secondRequest = { 208 + url, 209 + curatorId: curatorId.value, 210 + }; 211 + 212 + const secondResult = await useCase.execute(secondRequest); 213 + expect(secondResult.isOk()).toBe(true); 214 + const secondResponse = secondResult.unwrap(); 215 + 216 + // Should have different URL card IDs 217 + expect(secondResponse.urlCardId).not.toBe(firstResponse.urlCardId); 218 + 219 + // Should have two separate URL cards 220 + const savedCards = cardRepository.getAllCards(); 221 + expect(savedCards).toHaveLength(2); 222 + 223 + const urlCards = savedCards.filter( 224 + (card) => card.content.type === CardTypeEnum.URL, 225 + ); 226 + expect(urlCards).toHaveLength(2); // Two separate URL cards 227 + 228 + // Verify each card belongs to the correct curator 229 + const firstUserCard = urlCards.find((card) => 230 + card.props.curatorId.equals(otherCuratorId), 231 + ); 232 + const secondUserCard = urlCards.find((card) => 233 + card.props.curatorId.equals(curatorId), 234 + ); 235 + 236 + expect(firstUserCard).toBeDefined(); 237 + expect(secondUserCard).toBeDefined(); 238 + }); 239 + 240 + it('should create new URL card when no one has URL card with that URL yet', async () => { 241 + const url = 'https://example.com/brand-new'; 242 + 243 + // Verify no cards exist initially 244 + expect(cardRepository.getAllCards()).toHaveLength(0); 245 + 246 + const request = { 247 + url, 248 + curatorId: curatorId.value, 249 + }; 250 + 251 + const result = await useCase.execute(request); 252 + 253 + expect(result.isOk()).toBe(true); 254 + const response = result.unwrap(); 255 + expect(response.urlCardId).toBeDefined(); 256 + 257 + // Verify new URL card was created 258 + const savedCards = cardRepository.getAllCards(); 259 + expect(savedCards).toHaveLength(1); 260 + 261 + const urlCard = savedCards[0]; 262 + expect(urlCard?.content.type).toBe(CardTypeEnum.URL); 263 + expect(urlCard?.props.curatorId.equals(curatorId)).toBe(true); 264 + }); 191 265 }); 192 266 193 267 describe('Collection handling', () => {