@prismicio/e2e-tests-utils 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +16 -9
  2. package/dist/clients/apiClient.cjs +39 -0
  3. package/dist/clients/apiClient.cjs.map +1 -0
  4. package/dist/clients/apiClient.d.ts +30 -0
  5. package/dist/clients/apiClient.js +39 -0
  6. package/dist/clients/apiClient.js.map +1 -0
  7. package/dist/clients/authenticationApi.cjs +54 -34
  8. package/dist/clients/authenticationApi.cjs.map +1 -1
  9. package/dist/clients/authenticationApi.d.ts +13 -5
  10. package/dist/clients/authenticationApi.js +55 -35
  11. package/dist/clients/authenticationApi.js.map +1 -1
  12. package/dist/clients/contentApi.cjs +12 -48
  13. package/dist/clients/contentApi.cjs.map +1 -1
  14. package/dist/clients/contentApi.d.ts +5 -6
  15. package/dist/clients/contentApi.js +12 -48
  16. package/dist/clients/contentApi.js.map +1 -1
  17. package/dist/clients/coreApi.cjs +36 -31
  18. package/dist/clients/coreApi.cjs.map +1 -1
  19. package/dist/clients/coreApi.d.ts +21 -3
  20. package/dist/clients/coreApi.js +37 -32
  21. package/dist/clients/coreApi.js.map +1 -1
  22. package/dist/clients/customTypesApi.cjs +48 -42
  23. package/dist/clients/customTypesApi.cjs.map +1 -1
  24. package/dist/clients/customTypesApi.d.ts +34 -6
  25. package/dist/clients/customTypesApi.js +49 -43
  26. package/dist/clients/customTypesApi.js.map +1 -1
  27. package/dist/clients/migrationApi.cjs +30 -29
  28. package/dist/clients/migrationApi.cjs.map +1 -1
  29. package/dist/clients/migrationApi.d.ts +25 -5
  30. package/dist/clients/migrationApi.js +31 -30
  31. package/dist/clients/migrationApi.js.map +1 -1
  32. package/dist/index.cjs +1 -1
  33. package/dist/index.js +2 -2
  34. package/dist/managers/repositories.cjs +19 -9
  35. package/dist/managers/repositories.cjs.map +1 -1
  36. package/dist/managers/repositories.d.ts +2 -2
  37. package/dist/managers/repositories.js +23 -13
  38. package/dist/managers/repositories.js.map +1 -1
  39. package/dist/managers/repository.cjs +5 -0
  40. package/dist/managers/repository.cjs.map +1 -1
  41. package/dist/managers/repository.d.ts +6 -4
  42. package/dist/managers/repository.js +5 -0
  43. package/dist/managers/repository.js.map +1 -1
  44. package/dist/utils/log.cjs +4 -0
  45. package/dist/utils/log.cjs.map +1 -1
  46. package/dist/utils/log.d.ts +2 -0
  47. package/dist/utils/log.js +4 -0
  48. package/dist/utils/log.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/clients/apiClient.ts +48 -0
  51. package/src/clients/authenticationApi.ts +52 -50
  52. package/src/clients/contentApi.ts +18 -24
  53. package/src/clients/coreApi.ts +36 -42
  54. package/src/clients/customTypesApi.ts +34 -59
  55. package/src/clients/migrationApi.ts +33 -45
  56. package/src/managers/repositories.ts +26 -20
  57. package/src/managers/repository.ts +17 -7
  58. package/src/utils/log.ts +11 -0
@@ -1,13 +1,10 @@
1
1
  import { SetupConfiguration, UrlConfig } from "../types";
2
2
 
3
- import {
4
- AuthenticationClient,
5
- createAuthenticationApiClient,
6
- } from "../clients/authenticationApi";
7
- import { createCoreApiClient } from "../clients/coreApi";
8
- import { createCustomTypesApiClient } from "../clients/customTypesApi";
3
+ import { AuthenticationApiClient } from "../clients/authenticationApi";
4
+ import { CoreApiClient } from "../clients/coreApi";
5
+ import { CustomTypesApiClient } from "../clients/customTypesApi";
9
6
  import { ManageV2Client } from "../clients/manageV2";
10
- import { createMigrationApiClient } from "../clients/migrationApi";
7
+ import { MigrationApiClient } from "../clients/migrationApi";
11
8
  import { WroomClient } from "../clients/wroom";
12
9
  import { EnvVariableManager } from "../utils/envVariableManager";
13
10
  import { logHttpResponse, logger } from "../utils/log";
@@ -41,7 +38,7 @@ export class RepositoriesManager {
41
38
  urlConfig: UrlConfig;
42
39
  };
43
40
  private readonly wroomClient: WroomClient;
44
- private readonly authClient: AuthenticationClient;
41
+ private readonly authClient: AuthenticationApiClient;
45
42
  private readonly manageV2Client: ManageV2Client;
46
43
  /**
47
44
  * helper to keep track of repositories across independent test phases (setup,
@@ -70,7 +67,7 @@ export class RepositoriesManager {
70
67
  this.config.urlConfig.baseURL,
71
68
  this.config.authConfig,
72
69
  );
73
- this.authClient = createAuthenticationApiClient(
70
+ this.authClient = new AuthenticationApiClient(
74
71
  this.config.urlConfig.authenticationApi,
75
72
  this.config.authConfig,
76
73
  );
@@ -139,9 +136,12 @@ export class RepositoriesManager {
139
136
  }
140
137
  this.repositories.add(repositoryName);
141
138
 
142
- profiler.done({ message: `created repository '${repositoryName}'` });
143
-
144
139
  const repository = this.getRepositoryManager(repositoryName);
140
+ const version = await repository.getDeployedVersion();
141
+
142
+ profiler.done({
143
+ message: `created repository '${repositoryName}', Wroom version is "${version}"`,
144
+ });
145
145
  await repository.configure(config);
146
146
 
147
147
  return repository;
@@ -190,23 +190,29 @@ export class RepositoriesManager {
190
190
  /**
191
191
  * Return a repository utilities object for a repository.
192
192
  *
193
- * @param name - The name of the repository.
193
+ * @param repository - The name of the repository.
194
194
  */
195
- getRepositoryManager(name: string): RepositoryManager {
195
+ getRepositoryManager(repository: string): RepositoryManager {
196
196
  const { urlConfig } = this.config;
197
- const customTypeClient = createCustomTypesApiClient(
197
+ const authToken = () => this.authClient.getToken();
198
+ const customTypeClient = new CustomTypesApiClient(
198
199
  urlConfig.customTypesApi,
199
- name,
200
- this.authClient,
200
+ {
201
+ authToken,
202
+ repository,
203
+ },
201
204
  );
202
- const coreApiUrl = getRepositoryUrl(urlConfig.baseURL, name);
203
- const coreApiClient = createCoreApiClient(coreApiUrl, this.authClient);
205
+ const coreApiUrl = getRepositoryUrl(urlConfig.baseURL, repository);
206
+ const coreApiClient = new CoreApiClient(coreApiUrl, authToken);
204
207
  const migrationApiClient = urlConfig.migrationApi
205
- ? createMigrationApiClient(urlConfig.migrationApi, name, this.authClient)
208
+ ? new MigrationApiClient(urlConfig.migrationApi, {
209
+ authToken,
210
+ repository,
211
+ })
206
212
  : undefined;
207
213
 
208
214
  return new RepositoryManager(
209
- name,
215
+ repository,
210
216
  coreApiClient,
211
217
  this.authClient,
212
218
  this.wroomClient,
@@ -6,15 +6,15 @@ import {
6
6
  SharedSlice,
7
7
  } from "@prismicio/types-internal/lib/customtypes";
8
8
 
9
- import type { AuthenticationClient } from "../clients/authenticationApi";
9
+ import { AuthenticationApiClient } from "../clients/authenticationApi";
10
10
  import { ContentApiClient } from "../clients/contentApi";
11
11
  import type { CoreClient } from "../clients/coreApi";
12
- import { CustomTypesClient } from "../clients/customTypesApi";
12
+ import { CustomTypesApiClient } from "../clients/customTypesApi";
13
13
  import { ManageV2Client } from "../clients/manageV2";
14
14
  import {
15
15
  DocumentPayload,
16
16
  DocumentResponse,
17
- MigrationClient,
17
+ MigrationApiClient,
18
18
  } from "../clients/migrationApi";
19
19
  import { WroomClient } from "../clients/wroom";
20
20
  import { logHttpResponse, logger } from "../utils/log";
@@ -25,10 +25,10 @@ export class RepositoryManager {
25
25
  constructor(
26
26
  readonly name: string,
27
27
  private readonly coreApiClient: CoreClient,
28
- private readonly authApiClient: AuthenticationClient,
28
+ private readonly authApiClient: AuthenticationApiClient,
29
29
  private readonly wroomClient: WroomClient,
30
- private readonly customTypesApiClient: CustomTypesClient,
31
- private readonly migrationApiClient: MigrationClient | undefined,
30
+ private readonly customTypesApiClient: CustomTypesApiClient,
31
+ private readonly migrationApiClient: MigrationApiClient | undefined,
32
32
  private readonly manageV2Client: ManageV2Client,
33
33
  ) {}
34
34
 
@@ -37,7 +37,6 @@ export class RepositoryManager {
37
37
  config.defaultLocale || config.locales || config.customLocale;
38
38
  if (hasLangConfig) {
39
39
  const languages = await this.coreApiClient.getLanguages();
40
-
41
40
  // default locale must be set first
42
41
  if (config.defaultLocale) {
43
42
  const master = languages.find(({ is_master }) => is_master === true);
@@ -105,6 +104,17 @@ export class RepositoryManager {
105
104
  return new ContentApiClient(this.getBaseCdnURL(), config);
106
105
  }
107
106
 
107
+ /** @returns the Wroom commit hash deployed on the current repository */
108
+ async getDeployedVersion(): Promise<string | undefined> {
109
+ const response = await this.wroomClient.get(
110
+ this.name,
111
+ "underground/834b34f16f451e00f268dd5c8c81d16e3c020275",
112
+ );
113
+
114
+ // Somehow axios directly parses the text response `Prismic version: <commit hash> into a version attribute
115
+ return response.data.version;
116
+ }
117
+
108
118
  /**
109
119
  * Set additional standard locales for a repository in Wroom, does not fail if
110
120
  * the locales already exist.
package/src/utils/log.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { APIResponse } from "@playwright/test";
1
2
  import { AxiosResponse } from "axios";
2
3
  import { createLogger, format, transports } from "winston";
3
4
 
@@ -13,6 +14,16 @@ export const logHttpResponse = (response: AxiosResponse): void => {
13
14
  );
14
15
  };
15
16
 
17
+ export const logPlaywrightApiResponse = async (
18
+ response: APIResponse,
19
+ ): Promise<void> => {
20
+ logger.info(
21
+ `Call to ${response.url()} failed, received [${response.status()}] ${JSON.stringify(
22
+ await response.text(),
23
+ )}`,
24
+ );
25
+ };
26
+
16
27
  const { combine, printf } = format;
17
28
 
18
29
  const customFormat = printf(({ message, durationMs }) => {