@prismicio/e2e-tests-utils 1.12.0 → 1.14.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.
- package/dist/clients/assetApi.cjs +16 -0
- package/dist/clients/assetApi.cjs.map +1 -1
- package/dist/clients/assetApi.d.ts +21 -0
- package/dist/clients/assetApi.js +16 -0
- package/dist/clients/assetApi.js.map +1 -1
- package/dist/clients/coreApi.cjs +67 -0
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.ts +47 -0
- package/dist/clients/coreApi.js +67 -0
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/managers/repository.cjs +54 -1
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +32 -2
- package/dist/managers/repository.js +54 -1
- package/dist/managers/repository.js.map +1 -1
- package/package.json +1 -1
- package/src/clients/assetApi.ts +34 -0
- package/src/clients/coreApi.ts +103 -0
- package/src/index.ts +2 -0
- package/src/managers/repository.ts +69 -1
package/src/clients/coreApi.ts
CHANGED
|
@@ -8,6 +8,12 @@ type Language = {
|
|
|
8
8
|
is_master: boolean;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
export type Release = {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
migration: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
11
17
|
export type CoreApiDocumentCreationPayload = {
|
|
12
18
|
title: string;
|
|
13
19
|
locale?: string;
|
|
@@ -47,6 +53,22 @@ export type CoreApiDocumentCreationResponse = {
|
|
|
47
53
|
}[];
|
|
48
54
|
};
|
|
49
55
|
|
|
56
|
+
export type CoreApiDocumentsPayload = {
|
|
57
|
+
language?: string;
|
|
58
|
+
limit?: number;
|
|
59
|
+
statuses?: string[];
|
|
60
|
+
groupLangIds?: string[];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type CoreApiDocumentsResponse = {
|
|
64
|
+
total: number;
|
|
65
|
+
cursor: string;
|
|
66
|
+
results: CoreApiDocumentCreationResponse[];
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
export type CoreApiDocumentData = Record<string, any>;
|
|
71
|
+
|
|
50
72
|
export class CoreApiClient extends AuthenticatedApiClient {
|
|
51
73
|
/**
|
|
52
74
|
* @example To instantiate the class:
|
|
@@ -82,6 +104,28 @@ export class CoreApiClient extends AuthenticatedApiClient {
|
|
|
82
104
|
return (await result.json()).languages;
|
|
83
105
|
}
|
|
84
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves all releases, including the migration release.
|
|
109
|
+
*
|
|
110
|
+
* @returns An array of release metadata.
|
|
111
|
+
*/
|
|
112
|
+
async getReleases(): Promise<Release[]> {
|
|
113
|
+
const profiler = logger.startTimer();
|
|
114
|
+
const context = await this.getContext();
|
|
115
|
+
const result = await context.get("core/releases", {
|
|
116
|
+
params: { include_migration_releases: true },
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (200 !== result.status() || !(await result.json()).results) {
|
|
120
|
+
await logPlaywrightApiResponse(result);
|
|
121
|
+
throw new Error("Could not get releases from the core api.");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
profiler.done({ message: "retrieved releases" });
|
|
125
|
+
|
|
126
|
+
return (await result.json()).results;
|
|
127
|
+
}
|
|
128
|
+
|
|
85
129
|
async createDraft(
|
|
86
130
|
data: CoreApiDocumentCreationPayload,
|
|
87
131
|
): Promise<CoreApiDocumentCreationResponse> {
|
|
@@ -111,4 +155,63 @@ export class CoreApiClient extends AuthenticatedApiClient {
|
|
|
111
155
|
throw new Error(`Could not publish document with id ${documentId}`);
|
|
112
156
|
}
|
|
113
157
|
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Retrieves documents.
|
|
161
|
+
*
|
|
162
|
+
* @param args - Configure which documents are retrieved.
|
|
163
|
+
*
|
|
164
|
+
* @returns A paginated set of documents.
|
|
165
|
+
*/
|
|
166
|
+
async getDocuments(
|
|
167
|
+
args: CoreApiDocumentsPayload,
|
|
168
|
+
): Promise<CoreApiDocumentsResponse> {
|
|
169
|
+
const context = await this.getContext();
|
|
170
|
+
const result = await context.post("core/documents/search", {
|
|
171
|
+
data: args,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
if (200 !== result.status()) {
|
|
175
|
+
await logPlaywrightApiResponse(result);
|
|
176
|
+
throw new Error("Could not search documents");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return result.json();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Retrieves data for a specific document version.
|
|
184
|
+
*
|
|
185
|
+
* @param versionId - The document's version ID.
|
|
186
|
+
*
|
|
187
|
+
* @returns The document's version data.
|
|
188
|
+
*/
|
|
189
|
+
async getDocumentData(versionId: string): Promise<CoreApiDocumentData> {
|
|
190
|
+
const context = await this.getContext();
|
|
191
|
+
const result = await context.get(`core/documents/data/${versionId}`);
|
|
192
|
+
|
|
193
|
+
if (200 !== result.status()) {
|
|
194
|
+
await logPlaywrightApiResponse(result);
|
|
195
|
+
throw new Error("Could not retrieve document data");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return result.json();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Publishes a release.
|
|
203
|
+
*
|
|
204
|
+
* @param id - The ID of the release.
|
|
205
|
+
*
|
|
206
|
+
* @returns A Promise that resolves when the release is published.
|
|
207
|
+
*/
|
|
208
|
+
async publishRelease(id: string): Promise<void> {
|
|
209
|
+
const context = await this.getContext();
|
|
210
|
+
const result = await context.post(`core/releases/${id}/publish`);
|
|
211
|
+
|
|
212
|
+
if (200 !== result.status()) {
|
|
213
|
+
await logPlaywrightApiResponse(result);
|
|
214
|
+
throw new Error("Could not publish release ${id}");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
114
217
|
}
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,10 @@ import {
|
|
|
15
15
|
CoreApiClient,
|
|
16
16
|
CoreApiDocumentCreationPayload,
|
|
17
17
|
CoreApiDocumentCreationResponse,
|
|
18
|
+
CoreApiDocumentData,
|
|
19
|
+
CoreApiDocumentsPayload,
|
|
20
|
+
CoreApiDocumentsResponse,
|
|
21
|
+
Release,
|
|
18
22
|
} from "../clients/coreApi";
|
|
19
23
|
import { CustomTypesApiClient } from "../clients/customTypesApi";
|
|
20
24
|
import { IntegrationFieldsClient } from "../clients/integrationFields";
|
|
@@ -279,6 +283,19 @@ export class RepositoryManager {
|
|
|
279
283
|
profiler.done({ message: `default locale set to '${locale}'` });
|
|
280
284
|
}
|
|
281
285
|
|
|
286
|
+
/**
|
|
287
|
+
* Retrieves documents.
|
|
288
|
+
*
|
|
289
|
+
* @param args - Configure which documents are retrieved.
|
|
290
|
+
*
|
|
291
|
+
* @returns A paginated set of documents.
|
|
292
|
+
*/
|
|
293
|
+
async getDocuments(
|
|
294
|
+
args: CoreApiDocumentsPayload,
|
|
295
|
+
): Promise<CoreApiDocumentsResponse> {
|
|
296
|
+
return this.coreApiClient.getDocuments(args);
|
|
297
|
+
}
|
|
298
|
+
|
|
282
299
|
/**
|
|
283
300
|
* Creates a release.
|
|
284
301
|
*
|
|
@@ -298,10 +315,50 @@ export class RepositoryManager {
|
|
|
298
315
|
return response.data;
|
|
299
316
|
}
|
|
300
317
|
|
|
318
|
+
/**
|
|
319
|
+
* Retrieves the migration release.
|
|
320
|
+
*
|
|
321
|
+
* @returns The migration relese metadata.
|
|
322
|
+
*/
|
|
323
|
+
async getMigrationRelease(): Promise<Release> {
|
|
324
|
+
const releases = await this.coreApiClient.getReleases();
|
|
325
|
+
const migrationRelease = releases.find((release) => release.migration);
|
|
326
|
+
if (!migrationRelease) {
|
|
327
|
+
throw new Error(`The repository does not have a migration release`);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return migrationRelease;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Publishes a release.
|
|
335
|
+
*
|
|
336
|
+
* @param id - The ID of the release.
|
|
337
|
+
*
|
|
338
|
+
* @returns A Promise that resolves when the release is published and a new
|
|
339
|
+
* master ref is available.
|
|
340
|
+
*/
|
|
341
|
+
async publishRelease(id: string): Promise<void> {
|
|
342
|
+
const profiler = logger.startTimer();
|
|
343
|
+
|
|
344
|
+
const contentApi = this.getContentApiClient();
|
|
345
|
+
const masterRef = await contentApi.getMasterRef();
|
|
346
|
+
await this.coreApiClient.publishRelease(id);
|
|
347
|
+
await expect
|
|
348
|
+
.poll(async () => contentApi.getMasterRef(), {
|
|
349
|
+
timeout: 10_000,
|
|
350
|
+
message: "Waiting for new master ref to be available",
|
|
351
|
+
})
|
|
352
|
+
.not.toBe(masterRef);
|
|
353
|
+
|
|
354
|
+
profiler.done({
|
|
355
|
+
message: `release '${id}' published and new master ref available`,
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
301
359
|
/**
|
|
302
360
|
* Deletes a repository release.
|
|
303
361
|
*
|
|
304
|
-
* @param repository - The name of the repository.
|
|
305
362
|
* @param id - The ID of the release to be deleted.
|
|
306
363
|
*/
|
|
307
364
|
async deleteRelease(id: string): Promise<void> {
|
|
@@ -753,6 +810,17 @@ export class RepositoryManager {
|
|
|
753
810
|
return result;
|
|
754
811
|
}
|
|
755
812
|
|
|
813
|
+
/**
|
|
814
|
+
* Retrieves data for a specific document version.
|
|
815
|
+
*
|
|
816
|
+
* @param versionId - The document's version ID.
|
|
817
|
+
*
|
|
818
|
+
* @returns The document's version data.
|
|
819
|
+
*/
|
|
820
|
+
async getDocumentData(versionId: string): Promise<CoreApiDocumentData> {
|
|
821
|
+
return await this.coreApiClient.getDocumentData(versionId);
|
|
822
|
+
}
|
|
823
|
+
|
|
756
824
|
async setupIntegrationFields(
|
|
757
825
|
integrationFields: IntegrationFieldConfig[],
|
|
758
826
|
): Promise<void> {
|