1+ import { describe , it , expect } from 'vitest' ;
2+ import { validateCardPlatforms , diffCardPlatforms } from '../cards' ;
3+
4+ describe ( 'validateCardPlatforms' , ( ) => {
5+ it ( 'passes with valid platforms' , ( ) => {
6+ const result = validateCardPlatforms ( [ 'github' , 'linkedin' ] ) ;
7+ expect ( result . valid ) . toBe ( true ) ;
8+ expect ( result . errors ) . toHaveLength ( 0 ) ;
9+ } ) ;
10+
11+ it ( 'fails with empty array' , ( ) => {
12+ const result = validateCardPlatforms ( [ ] ) ;
13+ expect ( result . valid ) . toBe ( false ) ;
14+ expect ( result . errors ) . toContain ( 'At least one platform is required.' ) ;
15+ } ) ;
16+
17+ it ( 'fails with unknown platform' , ( ) => {
18+ const result = validateCardPlatforms ( [ 'github' , 'myspace' ] ) ;
19+ expect ( result . valid ) . toBe ( false ) ;
20+ expect ( result . errors . some ( e => e . includes ( 'myspace' ) ) ) . toBe ( true ) ;
21+ } ) ;
22+
23+ it ( 'fails with duplicate platforms' , ( ) => {
24+ const result = validateCardPlatforms ( [ 'github' , 'github' ] ) ;
25+ expect ( result . valid ) . toBe ( false ) ;
26+ expect ( result . errors . some ( e => e . includes ( 'Duplicate' ) ) ) . toBe ( true ) ;
27+ } ) ;
28+
29+ it ( 'passes with exactly 10 platforms' , ( ) => {
30+ const platforms = [ 'github' , 'linkedin' , 'twitter' , 'youtube' , 'twitch' ,
31+ 'discord' , 'devto' , 'medium' , 'dribbble' , 'leetcode' ] ;
32+ const result = validateCardPlatforms ( platforms ) ;
33+ expect ( result . valid ) . toBe ( true ) ;
34+ } ) ;
35+
36+ it ( 'fails with more than 10 platforms' , ( ) => {
37+ const platforms = [ 'github' , 'linkedin' , 'twitter' , 'youtube' , 'twitch' ,
38+ 'discord' , 'devto' , 'medium' , 'dribbble' , 'leetcode' , 'npm' ] ;
39+ const result = validateCardPlatforms ( platforms ) ;
40+ expect ( result . valid ) . toBe ( false ) ;
41+ expect ( result . errors . some ( e => e . includes ( 'Maximum 10' ) ) ) . toBe ( true ) ;
42+ } ) ;
43+
44+ it ( 'fails with all invalid platforms' , ( ) => {
45+ const result = validateCardPlatforms ( [ 'myspace' , 'bebo' ] ) ;
46+ expect ( result . valid ) . toBe ( false ) ;
47+ expect ( result . errors . length ) . toBeGreaterThanOrEqual ( 2 ) ;
48+ } ) ;
49+ } ) ;
50+
51+ describe ( 'diffCardPlatforms' , ( ) => {
52+ it ( 'correctly identifies added, removed, unchanged' , ( ) => {
53+ const diff = diffCardPlatforms ( [ 'github' , 'linkedin' ] , [ 'github' , 'twitter' ] ) ;
54+ expect ( diff . added ) . toEqual ( [ 'twitter' ] ) ;
55+ expect ( diff . removed ) . toEqual ( [ 'linkedin' ] ) ;
56+ expect ( diff . unchanged ) . toEqual ( [ 'github' ] ) ;
57+ } ) ;
58+
59+ it ( 'handles empty old card' , ( ) => {
60+ const diff = diffCardPlatforms ( [ ] , [ 'github' ] ) ;
61+ expect ( diff . added ) . toEqual ( [ 'github' ] ) ;
62+ expect ( diff . removed ) . toEqual ( [ ] ) ;
63+ expect ( diff . unchanged ) . toEqual ( [ ] ) ;
64+ } ) ;
65+
66+ it ( 'handles identical cards' , ( ) => {
67+ const diff = diffCardPlatforms ( [ 'github' ] , [ 'github' ] ) ;
68+ expect ( diff . added ) . toEqual ( [ ] ) ;
69+ expect ( diff . removed ) . toEqual ( [ ] ) ;
70+ expect ( diff . unchanged ) . toEqual ( [ 'github' ] ) ;
71+ } ) ;
72+ } ) ;
0 commit comments