|
| 1 | +const fs = require("fs"); |
| 2 | +const path = require("node:path"); |
| 3 | +const { |
| 4 | + deployAndRun, |
| 5 | + runtests, |
| 6 | + GQLHeaders, |
| 7 | + endpoint, |
| 8 | + getTestDescription, |
| 9 | +} = require("../../../tests/gqltest.js"); |
| 10 | + |
| 11 | +testDescription = getTestDescription("snippets", __dirname); |
| 12 | + |
| 13 | +const requestsFile = path.join(path.dirname(__dirname), "operations.graphql"); |
| 14 | +const requests = fs.readFileSync(requestsFile, "utf8").toString(); |
| 15 | + |
| 16 | +describe(testDescription, function () { |
| 17 | + // just deploy |
| 18 | + deployAndRun(__dirname, [], undefined); |
| 19 | + |
| 20 | + // and then run with various JWTs |
| 21 | + runtests( |
| 22 | + "regions-in", |
| 23 | + endpoint, |
| 24 | + new GQLHeaders().withToken( |
| 25 | + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1IiwicmVnaW9ucyI6WyJJTiJdfQ.hDi3-qaIOSFKzlFvaXwSh0trXC3vjiOehSKE0OxgOdE" |
| 26 | + ), |
| 27 | + [ |
| 28 | + { |
| 29 | + label: "customers", |
| 30 | + query: requests, |
| 31 | + operationName: "Customers", |
| 32 | + expected: { |
| 33 | + customers: [ |
| 34 | + { |
| 35 | + id: "10", |
| 36 | + name: "Salma Khan ", |
| 37 | + city: "Delhi ", |
| 38 | + region: "IN ", |
| 39 | + }, |
| 40 | + ], |
| 41 | + }, |
| 42 | + }, |
| 43 | + ] |
| 44 | + ); |
| 45 | + runtests( |
| 46 | + "regions-in-uk", |
| 47 | + endpoint, |
| 48 | + new GQLHeaders().withToken( |
| 49 | + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1IiwicmVnaW9ucyI6WyJJTiIsIlVLIl19.CRD85IIMMwjaFebtQ_p3AjSoUM6KtH4gvjcfLQfdmjw" |
| 50 | + ), |
| 51 | + [ |
| 52 | + { |
| 53 | + label: "customers", |
| 54 | + query: requests, |
| 55 | + operationName: "Customers", |
| 56 | + expected: { |
| 57 | + customers: [ |
| 58 | + { |
| 59 | + id: "3", |
| 60 | + name: "Salim Ali ", |
| 61 | + city: "London ", |
| 62 | + region: "UK ", |
| 63 | + }, |
| 64 | + { |
| 65 | + id: "4", |
| 66 | + name: "Jane Xiu ", |
| 67 | + city: "Edinburgh ", |
| 68 | + region: "UK ", |
| 69 | + }, |
| 70 | + { |
| 71 | + id: "10", |
| 72 | + name: "Salma Khan ", |
| 73 | + city: "Delhi ", |
| 74 | + region: "IN ", |
| 75 | + }, |
| 76 | + ], |
| 77 | + }, |
| 78 | + }, |
| 79 | + ] |
| 80 | + ); |
| 81 | + runtests( |
| 82 | + "regions-us-uk", |
| 83 | + endpoint, |
| 84 | + new GQLHeaders().withToken( |
| 85 | + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1IiwicmVnaW9ucyI6WyJVUyIsIlVLIl19.pf0-A6TN_hT-ldCvsZyqYGv4Twjm9s6wO1aatCjK9Aw" |
| 86 | + ), |
| 87 | + [ |
| 88 | + { |
| 89 | + label: "customers", |
| 90 | + query: requests, |
| 91 | + operationName: "Customers", |
| 92 | + expected: { |
| 93 | + customers: [ |
| 94 | + { |
| 95 | + id: "1", |
| 96 | + name: "Lucas Bill ", |
| 97 | + city: "Boston ", |
| 98 | + region: "US ", |
| 99 | + }, |
| 100 | + { |
| 101 | + id: "2", |
| 102 | + name: "Mandy Jones ", |
| 103 | + city: "Round Rock ", |
| 104 | + region: "US ", |
| 105 | + }, |
| 106 | + { |
| 107 | + id: "3", |
| 108 | + name: "Salim Ali ", |
| 109 | + city: "London ", |
| 110 | + region: "UK ", |
| 111 | + }, |
| 112 | + { |
| 113 | + id: "4", |
| 114 | + name: "Jane Xiu ", |
| 115 | + city: "Edinburgh ", |
| 116 | + region: "UK ", |
| 117 | + }, |
| 118 | + { |
| 119 | + id: "5", |
| 120 | + name: "John Doe ", |
| 121 | + city: "Miami ", |
| 122 | + region: "US ", |
| 123 | + }, |
| 124 | + { |
| 125 | + id: "6", |
| 126 | + name: "Jane Smith ", |
| 127 | + city: "San Francisco ", |
| 128 | + region: "US ", |
| 129 | + }, |
| 130 | + { |
| 131 | + id: "7", |
| 132 | + name: "Sandeep Bhushan ", |
| 133 | + city: "New York ", |
| 134 | + region: "US ", |
| 135 | + }, |
| 136 | + { |
| 137 | + id: "8", |
| 138 | + name: "George Han ", |
| 139 | + city: "Seattle ", |
| 140 | + region: "US ", |
| 141 | + }, |
| 142 | + { |
| 143 | + id: "9", |
| 144 | + name: "Asha Kumari ", |
| 145 | + city: "Chicago ", |
| 146 | + region: "US ", |
| 147 | + }, |
| 148 | + ], |
| 149 | + }, |
| 150 | + }, |
| 151 | + { |
| 152 | + label: "customers-filter", |
| 153 | + query: requests, |
| 154 | + operationName: "Customers", |
| 155 | + variables: { |
| 156 | + f: { city: { eq: "London" } }, |
| 157 | + }, |
| 158 | + expected: { |
| 159 | + customers: [ |
| 160 | + { |
| 161 | + id: "3", |
| 162 | + name: "Salim Ali ", |
| 163 | + city: "London ", |
| 164 | + region: "UK ", |
| 165 | + }, |
| 166 | + ], |
| 167 | + }, |
| 168 | + }, |
| 169 | + ] |
| 170 | + ); |
| 171 | +}); |
0 commit comments