|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | + |
| 3 | +import { transformCodeSamplesToGuideMethods } from '../snippets'; |
| 4 | +import { SnippetSamples } from '../types'; |
| 5 | + |
| 6 | +describe('init', () => { |
| 7 | + it('parses a multi line import', () => { |
| 8 | + expect( |
| 9 | + JSON.parse( |
| 10 | + transformCodeSamplesToGuideMethods({ |
| 11 | + csharp: { |
| 12 | + foo: { |
| 13 | + default: ` |
| 14 | + // Initialize the client |
| 15 | +var client = new QuerySuggestionsClient( |
| 16 | + new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") |
| 17 | +); |
| 18 | +
|
| 19 | +// Call the API |
| 20 | +var response = await client.CreateConfigAsync( |
| 21 | + new ConfigurationWithIndex |
| 22 | + { |
| 23 | + IndexName = "<YOUR_INDEX_NAME>", |
| 24 | + SourceIndices = new List<SourceIndex> |
| 25 | + { |
| 26 | + new SourceIndex |
| 27 | + { |
| 28 | + IndexName = "<YOUR_INDEX_NAME>", |
| 29 | + Facets = new List<Facet> { new Facet { Attribute = "test" } }, |
| 30 | + Generate = new List<List<string>> |
| 31 | + { |
| 32 | + new List<string> { "facetA", "facetB" }, |
| 33 | + new List<string> { "facetC" }, |
| 34 | + }, |
| 35 | + }, |
| 36 | + }, |
| 37 | + Languages = new Languages(new List<string> { "french" }), |
| 38 | + Exclude = new List<string> { "test" }, |
| 39 | + } |
| 40 | +); |
| 41 | +// >LOG |
| 42 | + `, |
| 43 | + }, |
| 44 | + }, |
| 45 | + } as unknown as SnippetSamples), |
| 46 | + ), |
| 47 | + ).toMatchInlineSnapshot(` |
| 48 | + { |
| 49 | + "csharp": { |
| 50 | + "foo": { |
| 51 | + "default": "var response = await client.CreateConfigAsync( |
| 52 | + new ConfigurationWithIndex |
| 53 | + { |
| 54 | + IndexName = "<YOUR_INDEX_NAME>", |
| 55 | + SourceIndices = new List<SourceIndex> |
| 56 | + { |
| 57 | + new SourceIndex |
| 58 | + { |
| 59 | + IndexName = "<YOUR_INDEX_NAME>", |
| 60 | + Facets = new List<Facet> { new Facet { Attribute = "test" } }, |
| 61 | + Generate = new List<List<string>> |
| 62 | + { |
| 63 | + new List<string> { "facetA", "facetB" }, |
| 64 | + new List<string> { "facetC" }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + Languages = new Languages(new List<string> { "french" }), |
| 69 | + Exclude = new List<string> { "test" }, |
| 70 | + } |
| 71 | + );", |
| 72 | + }, |
| 73 | + "init": { |
| 74 | + "default": "var client = new QuerySuggestionsClient( |
| 75 | + new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") |
| 76 | + );", |
| 77 | + }, |
| 78 | + }, |
| 79 | + } |
| 80 | + `); |
| 81 | + }); |
| 82 | + |
| 83 | + it('parses a single line import', () => { |
| 84 | + expect( |
| 85 | + JSON.parse( |
| 86 | + transformCodeSamplesToGuideMethods({ |
| 87 | + csharp: { |
| 88 | + foo: { |
| 89 | + default: ` |
| 90 | + // Initialize the client |
| 91 | +var client = new QuerySuggestionsClient(new Client("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION")); |
| 92 | +
|
| 93 | +// Call the API |
| 94 | +var response = await client.CreateConfigAsync( |
| 95 | + new ConfigurationWithIndex |
| 96 | + { |
| 97 | + IndexName = "<YOUR_INDEX_NAME>", |
| 98 | + SourceIndices = new List<SourceIndex> |
| 99 | + { |
| 100 | + new SourceIndex |
| 101 | + { |
| 102 | + IndexName = "<YOUR_INDEX_NAME>", |
| 103 | + Facets = new List<Facet> { new Facet { Attribute = "test" } }, |
| 104 | + Generate = new List<List<string>> |
| 105 | + { |
| 106 | + new List<string> { "facetA", "facetB" }, |
| 107 | + new List<string> { "facetC" }, |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | + Languages = new Languages(new List<string> { "french" }), |
| 112 | + Exclude = new List<string> { "test" }, |
| 113 | + } |
| 114 | +); |
| 115 | +// >LOG |
| 116 | + `, |
| 117 | + }, |
| 118 | + }, |
| 119 | + } as unknown as SnippetSamples), |
| 120 | + ), |
| 121 | + ).toMatchInlineSnapshot(` |
| 122 | + { |
| 123 | + "csharp": { |
| 124 | + "foo": { |
| 125 | + "default": "var response = await client.CreateConfigAsync( |
| 126 | + new ConfigurationWithIndex |
| 127 | + { |
| 128 | + IndexName = "<YOUR_INDEX_NAME>", |
| 129 | + SourceIndices = new List<SourceIndex> |
| 130 | + { |
| 131 | + new SourceIndex |
| 132 | + { |
| 133 | + IndexName = "<YOUR_INDEX_NAME>", |
| 134 | + Facets = new List<Facet> { new Facet { Attribute = "test" } }, |
| 135 | + Generate = new List<List<string>> |
| 136 | + { |
| 137 | + new List<string> { "facetA", "facetB" }, |
| 138 | + new List<string> { "facetC" }, |
| 139 | + }, |
| 140 | + }, |
| 141 | + }, |
| 142 | + Languages = new Languages(new List<string> { "french" }), |
| 143 | + Exclude = new List<string> { "test" }, |
| 144 | + } |
| 145 | + );", |
| 146 | + }, |
| 147 | + "init": { |
| 148 | + "default": "var client = new QuerySuggestionsClient(new Client("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION"));", |
| 149 | + }, |
| 150 | + }, |
| 151 | + } |
| 152 | + `); |
| 153 | + }); |
| 154 | +}); |
| 155 | + |
| 156 | +describe('initialize', () => { |
| 157 | + it("doesn't stop at `client`", () => { |
| 158 | + expect( |
| 159 | + JSON.parse( |
| 160 | + transformCodeSamplesToGuideMethods({ |
| 161 | + csharp: { |
| 162 | + foo: { |
| 163 | + default: ` |
| 164 | + // Initialize the client foo bar BAAAAAAAAAAAAAAAAAAAAAZ |
| 165 | +var client = new QuerySuggestionsClient( |
| 166 | + new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") |
| 167 | +); |
| 168 | +
|
| 169 | +// Call the API |
| 170 | +var response = await client.CreateConfigAsync( |
| 171 | + new ConfigurationWithIndex |
| 172 | + { |
| 173 | + IndexName = "<YOUR_INDEX_NAME>", |
| 174 | + SourceIndices = new List<SourceIndex> |
| 175 | + { |
| 176 | + new SourceIndex |
| 177 | + { |
| 178 | + IndexName = "<YOUR_INDEX_NAME>", |
| 179 | + Facets = new List<Facet> { new Facet { Attribute = "test" } }, |
| 180 | + Generate = new List<List<string>> |
| 181 | + { |
| 182 | + new List<string> { "facetA", "facetB" }, |
| 183 | + new List<string> { "facetC" }, |
| 184 | + }, |
| 185 | + }, |
| 186 | + }, |
| 187 | + Languages = new Languages(new List<string> { "french" }), |
| 188 | + Exclude = new List<string> { "test" }, |
| 189 | + } |
| 190 | +); |
| 191 | +// >LOG |
| 192 | + `, |
| 193 | + }, |
| 194 | + }, |
| 195 | + } as unknown as SnippetSamples), |
| 196 | + ), |
| 197 | + ).toMatchInlineSnapshot(` |
| 198 | + { |
| 199 | + "csharp": { |
| 200 | + "foo": { |
| 201 | + "default": "var response = await client.CreateConfigAsync( |
| 202 | + new ConfigurationWithIndex |
| 203 | + { |
| 204 | + IndexName = "<YOUR_INDEX_NAME>", |
| 205 | + SourceIndices = new List<SourceIndex> |
| 206 | + { |
| 207 | + new SourceIndex |
| 208 | + { |
| 209 | + IndexName = "<YOUR_INDEX_NAME>", |
| 210 | + Facets = new List<Facet> { new Facet { Attribute = "test" } }, |
| 211 | + Generate = new List<List<string>> |
| 212 | + { |
| 213 | + new List<string> { "facetA", "facetB" }, |
| 214 | + new List<string> { "facetC" }, |
| 215 | + }, |
| 216 | + }, |
| 217 | + }, |
| 218 | + Languages = new Languages(new List<string> { "french" }), |
| 219 | + Exclude = new List<string> { "test" }, |
| 220 | + } |
| 221 | + );", |
| 222 | + }, |
| 223 | + "init": { |
| 224 | + "default": "var client = new QuerySuggestionsClient( |
| 225 | + new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") |
| 226 | + );", |
| 227 | + }, |
| 228 | + }, |
| 229 | + } |
| 230 | + `); |
| 231 | + }); |
| 232 | +}); |
0 commit comments