index.mock.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import nock from "nock";
  2. import url from "url";
  3. const commonHeaders = [
  4. "access-control-allow-headers",
  5. "authorization,content-length,content-type,user-agent,x-airtable-application-id,x-airtable-user-agent,x-api-version,x-requested-with",
  6. "access-control-allow-methods",
  7. "DELETE,GET,OPTIONS,PATCH,POST,PUT",
  8. "access-control-allow-origin",
  9. "*",
  10. "airtable-uncompressed-content-length",
  11. "380",
  12. "Content-Type",
  13. "application/json; charset=utf-8",
  14. "Date",
  15. "Thu, 24 Jun 2021 12:24:32 GMT",
  16. "Server",
  17. "Tengine",
  18. "Set-Cookie",
  19. "brw=brwHislGvzT3Ws3Yf; path=/; expires=Fri, 24 Jun 2022 12:24:32 GMT; domain=.airtable.com; samesite=none; secure",
  20. "Strict-Transport-Security",
  21. "max-age=31536000; includeSubDomains; preload",
  22. "Vary",
  23. "Accept-Encoding",
  24. "X-Content-Type-Options",
  25. "nosniff",
  26. "X-Frame-Options",
  27. "DENY",
  28. "Content-Length",
  29. "233",
  30. "Connection",
  31. "Close",
  32. ];
  33. nock("https://api.airtable.com:443", { encodedQueryParams: true })
  34. .persist()
  35. .get("/v0/appKYl1H4k9g73sBT/posts")
  36. .query((query) => {
  37. if (query.pageSize !== "100") return false;
  38. if (query.filterByFormula === undefined) return false;
  39. return true;
  40. })
  41. .reply(
  42. 200,
  43. function () {
  44. const parsed = new url.URL(this.req.path, "http://example.com");
  45. const query = parsed.searchParams.get("filterByFormula");
  46. return JSON.stringify({
  47. offset: 0,
  48. records: [
  49. {
  50. fields: {
  51. query,
  52. },
  53. },
  54. ],
  55. });
  56. },
  57. commonHeaders,
  58. );
  59. nock("https://api.airtable.com:443", { encodedQueryParams: true })
  60. .get("/v0/appKYl1H4k9g73sBT/posts")
  61. .query({ pageSize: "100" })
  62. .reply(
  63. 200,
  64. [
  65. "1f8b0800000000000003954fc18ac23014fc157dc7a292562bdaa3c86a570f2215c5ad87da3cd7484cd634825aecb7fb82a0c74598c3639899375382c15c1b5e40f45382e01039a23fdaaea637dee517d58925346027503a4d09565889a41aa394bab6d446f25abb4e923cb3f8abcd95825cc47030ff9687c1f06bdc31f11e360d286c66cf94017fe7ad14c51eb9736965515962b38213525555cf8b5055a94a95e7bd88ccf3520577b219a4773c1147d7256081df64dda61f26be1f056114f65a8cb13529df9ba693b9d027b14bcc6c11dffedbf4d9228307cca9cf27d536f7073da8e6fb7c010000",
  66. ],
  67. [
  68. "access-control-allow-headers",
  69. "authorization,content-length,content-type,user-agent,x-airtable-application-id,x-airtable-user-agent,x-api-version,x-requested-with",
  70. "access-control-allow-methods",
  71. "DELETE,GET,OPTIONS,PATCH,POST,PUT",
  72. "access-control-allow-origin",
  73. "*",
  74. "airtable-uncompressed-content-length",
  75. "380",
  76. "content-encoding",
  77. "gzip",
  78. "Content-Type",
  79. "application/json; charset=utf-8",
  80. "Date",
  81. "Thu, 24 Jun 2021 12:24:32 GMT",
  82. "Server",
  83. "Tengine",
  84. "Set-Cookie",
  85. "brw=brwHislGvzT3Ws3Yf; path=/; expires=Fri, 24 Jun 2022 12:24:32 GMT; domain=.airtable.com; samesite=none; secure",
  86. "Strict-Transport-Security",
  87. "max-age=31536000; includeSubDomains; preload",
  88. "Vary",
  89. "Accept-Encoding",
  90. "X-Content-Type-Options",
  91. "nosniff",
  92. "X-Frame-Options",
  93. "DENY",
  94. "Content-Length",
  95. "233",
  96. "Connection",
  97. "Close",
  98. ],
  99. );
  100. nock("https://api.airtable.com:443", { encodedQueryParams: true })
  101. .get("/v0/appKYl1H4k9g73sBT/posts")
  102. .query({
  103. pageSize: "100",
  104. "sort%5B0%5D%5Bfield%5D": "title",
  105. "sort%5B0%5D%5Bdirection%5D": "desc",
  106. })
  107. .reply(
  108. 200,
  109. [
  110. "1f8b0800000000000003958f416bc2401085ff8ace31a86ca211cd518235d64391144b1b0f4976ac2beb6ebbbb426b30bfdd490bf59243857718debc6f785381c1521b6e217aab4070881a63f5b816fa53ec52f3f49c9ca1073b81b2c954605dee4ef62776c0d221a76d993b7cd7e69b6e34743c5b2fe56116cf172393ec61db03279c44621628a5ee6cb491bc0b17020d12ca53716cb6010bfc3e1bf7fd30f5fd2808a37032608cbd52f2566dfa50bcacce7cccbfd42891edd53e4e851476ffbf6ea5560e95232cb79c94a9bafe9d48759da94c79de9f917b5ea6a0f5a3cef0ae9fb6972ba8a00e5b7c010000",
  111. ],
  112. [
  113. "access-control-allow-headers",
  114. "authorization,content-length,content-type,user-agent,x-airtable-application-id,x-airtable-user-agent,x-api-version,x-requested-with",
  115. "access-control-allow-methods",
  116. "DELETE,GET,OPTIONS,PATCH,POST,PUT",
  117. "access-control-allow-origin",
  118. "*",
  119. "airtable-uncompressed-content-length",
  120. "380",
  121. "content-encoding",
  122. "gzip",
  123. "Content-Type",
  124. "application/json; charset=utf-8",
  125. "Date",
  126. "Thu, 24 Jun 2021 13:07:26 GMT",
  127. "Server",
  128. "Tengine",
  129. "Set-Cookie",
  130. "brw=brw0sykMWa9glzNWF; path=/; expires=Fri, 24 Jun 2022 13:07:25 GMT; domain=.airtable.com; samesite=none; secure",
  131. "Strict-Transport-Security",
  132. "max-age=31536000; includeSubDomains; preload",
  133. "Vary",
  134. "Accept-Encoding",
  135. "X-Content-Type-Options",
  136. "nosniff",
  137. "X-Frame-Options",
  138. "DENY",
  139. "Content-Length",
  140. "237",
  141. "Connection",
  142. "Close",
  143. ],
  144. );