Type-safe GraphQL client generator for Gleam
at v1.1.2 2.8 kB view raw
1import gleam/list 2import gleam/string 3import gleeunit/should 4import squall/internal/discovery 5 6// Test: Discover .gql files in a directory 7pub fn discover_graphql_files_test() { 8 let result = discovery.find_graphql_files("test/fixtures") 9 10 should.be_ok(result) 11 let assert Ok(files) = result 12 13 // Should find at least 2 files 14 let count = list.length(files) 15 should.be_true(count >= 2) 16 17 // All files should end with .gql 18 files 19 |> list.all(fn(file) { string.ends_with(file.path, ".gql") }) 20 |> should.be_true() 21} 22 23// Test: Extract operation name from file path 24pub fn extract_operation_name_test() { 25 let result = 26 discovery.extract_operation_name("test/fixtures/graphql/get_character.gql") 27 28 should.be_ok(result) 29 should.equal(result, Ok("get_character")) 30} 31 32// Test: Extract operation name from nested path 33pub fn extract_operation_name_nested_test() { 34 let result = 35 discovery.extract_operation_name( 36 "test/fixtures/nested/graphql/list_characters.gql", 37 ) 38 39 should.be_ok(result) 40 should.equal(result, Ok("list_characters")) 41} 42 43// Test: Invalid operation name (starts with number) 44pub fn invalid_operation_name_test() { 45 let result = 46 discovery.extract_operation_name("test/fixtures/graphql/123invalid.gql") 47 48 should.be_error(result) 49} 50 51// Test: Invalid operation name (contains hyphens) 52pub fn invalid_operation_name_hyphens_test() { 53 let result = 54 discovery.extract_operation_name("test/fixtures/graphql/get-character.gql") 55 56 should.be_error(result) 57} 58 59// Test: Valid operation name with underscores 60pub fn valid_operation_name_underscores_test() { 61 let result = 62 discovery.extract_operation_name( 63 "test/fixtures/graphql/get_character_by_id.gql", 64 ) 65 66 should.be_ok(result) 67 should.equal(result, Ok("get_character_by_id")) 68} 69 70// Test: Discover files returns sorted results 71pub fn discover_files_sorted_test() { 72 let result = discovery.find_graphql_files("test/fixtures") 73 74 should.be_ok(result) 75 let assert Ok(files) = result 76 77 // Get file paths 78 let paths = list.map(files, fn(f) { f.path }) 79 80 // Should be sorted alphabetically 81 let sorted_paths = list.sort(paths, string.compare) 82 should.equal(paths, sorted_paths) 83} 84 85// Test: Read file content 86pub fn read_file_content_test() { 87 let result = discovery.find_graphql_files("test/fixtures") 88 89 should.be_ok(result) 90 let assert Ok(files) = result 91 92 // Find the get_character file 93 let get_char_file = 94 files 95 |> list.find(fn(f) { string.contains(f.path, "get_character.gql") }) 96 97 should.be_ok(get_char_file) 98 let assert Ok(file) = get_char_file 99 100 // Content should contain the query keyword 101 string.contains(file.content, "query") 102 |> should.be_true() 103 104 // Content should contain GetCharacter 105 string.contains(file.content, "GetCharacter") 106 |> should.be_true() 107}