Skip to content

Commit 68e0ccc

Browse files
feat(releases): release.entry.getMany() (#2673)
1 parent d7a768d commit 68e0ccc

File tree

6 files changed

+112
-42
lines changed

6 files changed

+112
-42
lines changed

lib/adapters/REST/endpoints/release-entry.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { AxiosInstance } from 'contentful-sdk-core'
2-
import type { GetReleaseEntryParams } from '../../../common-types'
2+
import type {
3+
GetReleaseEntryParams,
4+
GetSpaceEnvironmentParams,
5+
QueryParams,
6+
} from '../../../common-types'
37
import type { RestEndpoint } from '../types'
48
import * as raw from './raw'
59

@@ -13,3 +17,15 @@ export const get: RestEndpoint<'ReleaseEntry', 'get'> = (
1317
`/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries/${params.entryId}`
1418
)
1519
}
20+
21+
export const getMany: RestEndpoint<'ReleaseEntry', 'getMany'> = (
22+
http: AxiosInstance,
23+
params: GetSpaceEnvironmentParams & QueryParams & { releaseId: string }
24+
) => {
25+
params.query = { ...params.query, 'sys.schemaVersion': 'Release.V2' }
26+
27+
return raw.get(
28+
http,
29+
`/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries`
30+
)
31+
}

lib/common-types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,10 @@ export type MRActions = {
18511851
params: GetReleaseEntryParams
18521852
return: EntryProps<any, any>
18531853
}
1854+
getMany: {
1855+
params: GetManyReleaseEntryParams
1856+
return: CollectionProp<EntryProps<any, any>>
1857+
}
18541858
}
18551859
ReleaseAction: {
18561860
get: {
@@ -2335,6 +2339,11 @@ export type GetReleaseEntryParams = GetSpaceEnvironmentParams & {
23352339
releaseId: string
23362340
entryId: string
23372341
}
2342+
2343+
export type GetManyReleaseEntryParams = GetSpaceEnvironmentParams & {
2344+
releaseId: string
2345+
}
2346+
23382347
export type GetSnapshotForContentTypeParams = GetSpaceEnvironmentParams & { contentTypeId: string }
23392348
export type GetSnapshotForEntryParams = GetSpaceEnvironmentParams & { entryId: string }
23402349
export type GetSpaceEnvAliasParams = GetSpaceParams & { environmentAliasId: string }

lib/plain/common-types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
GetBulkActionParams,
99
GetContentTypeParams,
1010
GetEnvironmentTemplateParams,
11+
GetManyReleaseEntryParams,
1112
GetOrganizationMembershipParams,
1213
GetOrganizationParams,
1314
GetReleaseEntryParams,
@@ -440,6 +441,24 @@ export type PlainClientAPI = {
440441
}
441442
>
442443
>
444+
getMany<T extends KeyValueMap = KeyValueMap>(
445+
params: OptionalDefaults<GetManyReleaseEntryParams>
446+
): Promise<
447+
CollectionProp<
448+
EntryProps<
449+
T,
450+
{
451+
release: {
452+
sys: {
453+
type: 'Link'
454+
linkType: 'Entry' | 'Asset'
455+
id: string
456+
}
457+
}
458+
}
459+
>
460+
>
461+
>
443462
}
444463
archive(params: OptionalDefaults<GetReleaseParams & { version: number }>): Promise<ReleaseProps>
445464
get(params: OptionalDefaults<GetReleaseParams>): Promise<ReleaseProps>

lib/plain/plain-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ export const createPlainClient = (
344344
release: {
345345
entry: {
346346
get: wrap(wrapParams, 'ReleaseEntry', 'get'),
347+
getMany: wrap(wrapParams, 'ReleaseEntry', 'getMany'),
347348
},
348349
archive: wrap(wrapParams, 'Release', 'archive'),
349350
get: wrap(wrapParams, 'Release', 'get'),

test/integration/releasev2-integration.test.ts

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { makeLink } from '../utils'
66

77
describe('Release Api v2', () => {
88
let entry: EntryProps
9+
let secondEntry: EntryProps
910
let release: ReleaseProps
1011
let createReleaseClient: PlainClientAPI
1112

@@ -29,6 +30,17 @@ describe('Release Api v2', () => {
2930
}
3031
)
3132

33+
secondEntry = await createReleaseClient.entry.create(
34+
{ ...defaultParams, contentTypeId: TestDefaults.contentType.withCrossSpaceReferenceId },
35+
{
36+
fields: {
37+
title: {
38+
'en-US': 'Second Test Entry for Release',
39+
},
40+
},
41+
}
42+
)
43+
3244
release = await createReleaseClient.release.create(defaultParams, {
3345
title: 'Test Release',
3446
entities: {
@@ -38,6 +50,10 @@ describe('Release Api v2', () => {
3850
entity: makeLink('Entry', entry.sys.id),
3951
action: 'publish',
4052
},
53+
{
54+
entity: makeLink('Entry', secondEntry.sys.id),
55+
action: 'publish',
56+
},
4157
],
4258
},
4359
})
@@ -51,22 +67,15 @@ describe('Release Api v2', () => {
5167
await createReleaseClient.entry.delete({
5268
entryId: entry.sys.id,
5369
})
70+
await createReleaseClient.entry.delete({
71+
entryId: secondEntry.sys.id,
72+
})
5473
await timeoutToCalmRateLimiting()
5574
})
5675

5776
describe('releaseSchemaVersion is provided as a default in client', () => {
58-
let clientWithSchemaDefault: PlainClientAPI
59-
beforeEach(() => {
60-
const defaultParams = {
61-
environmentId: TestDefaults.environmentId,
62-
spaceId: TestDefaults.spaceId,
63-
releaseSchemaVersion: 'Release.v2',
64-
}
65-
clientWithSchemaDefault = initPlainClient(defaultParams)
66-
})
67-
6877
it('release.create works', async () => {
69-
const newRelease = await clientWithSchemaDefault.release.create(
78+
const newRelease = await createReleaseClient.release.create(
7079
{
7180
environmentId: TestDefaults.environmentId,
7281
spaceId: TestDefaults.spaceId,
@@ -83,20 +92,20 @@ describe('Release Api v2', () => {
8392
)
8493
expect(newRelease.sys.schemaVersion).toEqual('Release.v2')
8594
// cleanup
86-
await clientWithSchemaDefault.release.delete({
95+
await createReleaseClient.release.delete({
8796
releaseId: newRelease.sys.id,
8897
})
8998
})
9099

91100
it('release.query works', async () => {
92-
const releases = await clientWithSchemaDefault.release.query({})
101+
const releases = await createReleaseClient.release.query({})
93102
const fetchedRelease = releases.items.find((item) => item.sys.id === release.sys.id)
94-
expect(fetchedRelease).toEqual(release)
103+
expect(fetchedRelease?.sys.id).toEqual(release?.sys.id)
95104
expect(releases.pages).toStrictEqual({})
96105
})
97106

98107
it('release.update works', async () => {
99-
const updatedRelease = await clientWithSchemaDefault.release.update(
108+
const updatedRelease = await createReleaseClient.release.update(
100109
{
101110
environmentId: TestDefaults.environmentId,
102111
spaceId: TestDefaults.spaceId,
@@ -111,13 +120,11 @@ describe('Release Api v2', () => {
111120
},
112121
items: [
113122
{
114-
entity: {
115-
sys: {
116-
type: 'Link',
117-
linkType: 'Entry',
118-
id: entry.sys.id,
119-
},
120-
},
123+
entity: makeLink('Entry', entry.sys.id),
124+
action: 'publish',
125+
},
126+
{
127+
entity: makeLink('Entry', secondEntry.sys.id),
121128
action: 'publish',
122129
},
123130
],
@@ -129,7 +136,7 @@ describe('Release Api v2', () => {
129136
})
130137

131138
it('release.entry.get works', async () => {
132-
const entryInSpace = await clientWithSchemaDefault.release.entry.get({
139+
const entryInSpace = await createReleaseClient.release.entry.get({
133140
releaseId: release.sys.id,
134141
entryId: entry.sys.id, // Using the same ID for simplicity
135142
environmentId: TestDefaults.environmentId,
@@ -138,6 +145,23 @@ describe('Release Api v2', () => {
138145
expect(entryInSpace.sys.id).toEqual(entry.sys.id)
139146
expect(entryInSpace.sys.release.sys.id).toEqual(release.sys.id)
140147
})
148+
149+
it('release.entry.getMany works', async () => {
150+
const response = await createReleaseClient.release.entry.getMany({
151+
releaseId: release.sys.id,
152+
153+
environmentId: TestDefaults.environmentId,
154+
spaceId: TestDefaults.spaceId,
155+
})
156+
157+
const entries = response.items as EntryProps[]
158+
const foundFirstEntry = entries.find((e) => e.sys.id === entry.sys.id)
159+
const foundSecondEntry = entries.find((e) => e.sys.id === secondEntry.sys.id)
160+
161+
expect(entries.length).toEqual(2)
162+
expect(foundFirstEntry?.sys.id).toEqual(entry.sys.id)
163+
expect(foundSecondEntry?.sys.id).toEqual(secondEntry.sys.id)
164+
})
141165
})
142166

143167
describe('releaseSchemaVersion is not provided as a default', () => {
@@ -192,13 +216,11 @@ describe('Release Api v2', () => {
192216
},
193217
items: [
194218
{
195-
entity: {
196-
sys: {
197-
type: 'Link',
198-
linkType: 'Entry',
199-
id: entry.sys.id,
200-
},
201-
},
219+
entity: makeLink('Entry', entry.sys.id),
220+
action: 'publish',
221+
},
222+
{
223+
entity: makeLink('Entry', secondEntry.sys.id),
202224
action: 'publish',
203225
},
204226
],

test/unit/adapters/REST/endpoints/release-entry.test.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest'
22
import { cloneMock } from '../../../mocks/entities'
33
import * as raw from '../../../../../lib/adapters/REST/endpoints/raw'
4-
import { get } from '../../../../../lib/adapters/REST/endpoints/release-entry'
4+
import { get, getMany } from '../../../../../lib/adapters/REST/endpoints/release-entry'
55
import { EntryProps } from '../../../../../lib/entities/entry'
66
import { GetReleaseEntryParams } from '../../../../../lib/contentful-management'
77

@@ -10,10 +10,6 @@ describe('Rest ReleaseEntry', () => {
1010
any,
1111
{ release: { sys: { type: 'Link'; linkType: 'Release'; id: string } } }
1212
>
13-
let result: EntryProps<
14-
any,
15-
{ release: { sys: { type: 'Link'; linkType: 'Release'; id: string } } }
16-
>
1713
let rawGetSpy: any
1814
let params: GetReleaseEntryParams
1915
let httpMock: any
@@ -28,7 +24,7 @@ describe('Rest ReleaseEntry', () => {
2824
releaseId: 'black-friday',
2925
entryId: 'abc123',
3026
}
31-
result = await get(httpMock, params)
27+
await get(httpMock, params)
3228
})
3329

3430
afterEach(() => {
@@ -42,11 +38,18 @@ describe('Rest ReleaseEntry', () => {
4238
)
4339
})
4440

45-
test('release.entry.get returns the correct entry', async () => {
46-
expect(result).toEqual(mockReleaseEntry)
47-
})
41+
test('release.entry.getMany calls raw.get with the correct URL and params', async () => {
42+
const expectedParams = {
43+
spaceId: 'space123',
44+
environmentId: 'master',
45+
releaseId: 'black-friday',
46+
}
47+
48+
await getMany(httpMock, expectedParams)
4849

49-
test('release.entry.get returns release metadata', async () => {
50-
expect(result.sys.release).toBeDefined()
50+
expect(rawGetSpy).toHaveBeenCalledWith(
51+
httpMock,
52+
'/spaces/space123/environments/master/releases/black-friday/entries'
53+
)
5154
})
5255
})

0 commit comments

Comments
 (0)