Skip to content

Commit 790f711

Browse files
committed
chore: fix linting errors in new test suites and lib/
1 parent 84d693a commit 790f711

11 files changed

Lines changed: 202 additions & 174 deletions

lib/adapters/REST/make-request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const makeRequest = async <R>({
2929
// @ts-ignore
3030
endpoints[entityType]?.[action]
3131

32-
console.debug(endpoint)
32+
console.debug(endpoint)
3333

3434
if (endpoint === undefined) {
3535
throw new Error('Unknown endpoint')

lib/common-types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,9 @@ type MRInternal<UA extends boolean> = {
568568

569569
(opts: MROpts<'ContentType', 'get', UA>): MRReturn<'ContentType', 'get'>
570570
(opts: MROpts<'ContentType', 'getMany', UA>): MRReturn<'ContentType', 'getMany'>
571-
(opts: MROpts<'ContentType', 'getManyWithCursor', UA>): MRReturn<'ContentType', 'getManyWithCursor'>
571+
(
572+
opts: MROpts<'ContentType', 'getManyWithCursor', UA>,
573+
): MRReturn<'ContentType', 'getManyWithCursor'>
572574
(opts: MROpts<'ContentType', 'update', UA>): MRReturn<'ContentType', 'update'>
573575
(opts: MROpts<'ContentType', 'create', UA>): MRReturn<'ContentType', 'create'>
574576
(opts: MROpts<'ContentType', 'createWithId', UA>): MRReturn<'ContentType', 'createWithId'>

lib/common-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function waitFor(ms = 1000) {
5252

5353
export function normalizeCursorPaginationParameters(
5454
query: BasicCursorPaginationOptions,
55-
): CursorBasedParams{
55+
): CursorBasedParams {
5656
const { pagePrev, pageNext, ...rest } = query
5757

5858
return {
@@ -82,7 +82,7 @@ const Pages = {
8282
const PAGE_KEYS = ['prev', 'next'] as const
8383

8484
export function normalizeCursorPaginationResponse<T>(
85-
data: CursorPaginatedCollectionProp<T>
85+
data: CursorPaginatedCollectionProp<T>,
8686
): CursorPaginatedCollectionProp<T> {
8787
const pages: { prev?: string; next?: string } = {}
8888

lib/create-environment-api.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import type {
77
CursorBasedParams,
88
QueryOptions,
99
} from './common-types'
10-
import { normalizeCursorPaginationParameters, normalizeCursorPaginationResponse } from './common-utils'
10+
import {
11+
normalizeCursorPaginationParameters,
12+
normalizeCursorPaginationResponse,
13+
} from './common-utils'
1114
import type { BasicQueryOptions, MakeRequest } from './common-types'
1215
import entities from './entities'
1316
import type { CreateAppInstallationProps } from './entities/app-installation'
@@ -76,7 +79,8 @@ export type ContentfulEnvironmentAPI = ReturnType<typeof createEnvironmentApi>
7679
*/
7780
export default function createEnvironmentApi(makeRequest: MakeRequest) {
7881
const { wrapEnvironment } = entities.environment
79-
const { wrapContentType, wrapContentTypeCollection, wrapContentTypeCursorPaginatedCollection } = entities.contentType
82+
const { wrapContentType, wrapContentTypeCollection, wrapContentTypeCursorPaginatedCollection } =
83+
entities.contentType
8084
const { wrapEntry, wrapEntryCollection, wrapEntryTypeCursorPaginatedCollection } = entities.entry
8185
const { wrapAsset, wrapAssetCollection, wrapAssetTypeCursorPaginatedCollection } = entities.asset
8286
const { wrapAssetKey } = entities.assetKey
@@ -523,7 +527,12 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
523527
environmentId: raw.sys.id,
524528
query: createRequestConfig({ query: normalizedQueryParams }).params,
525529
},
526-
}).then((data) => wrapContentTypeCursorPaginatedCollection(makeRequest, normalizeCursorPaginationResponse(data)))
530+
}).then((data) =>
531+
wrapContentTypeCursorPaginatedCollection(
532+
makeRequest,
533+
normalizeCursorPaginationResponse(data),
534+
),
535+
)
527536
},
528537

529538
/**
@@ -805,7 +814,12 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
805814
environmentId: raw.sys.id,
806815
query: createRequestConfig({ query: normalizedQueryParams }).params,
807816
},
808-
}).then((data) => wrapEntryTypeCursorPaginatedCollection(makeRequest, normalizeCursorPaginationResponse(data)))
817+
}).then((data) =>
818+
wrapEntryTypeCursorPaginatedCollection(
819+
makeRequest,
820+
normalizeCursorPaginationResponse(data),
821+
),
822+
)
809823
},
810824

811825
/**
@@ -1055,8 +1069,11 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
10551069
environmentId: raw.sys.id,
10561070
query: createRequestConfig({ query: normalizedQueryParams }).params,
10571071
},
1058-
}).then((data) =>
1059-
wrapAssetTypeCursorPaginatedCollection(makeRequest, normalizeCursorPaginationResponse(data))
1072+
}).then((data) =>
1073+
wrapAssetTypeCursorPaginatedCollection(
1074+
makeRequest,
1075+
normalizeCursorPaginationResponse(data),
1076+
),
10601077
)
10611078
},
10621079

lib/entities/content-type.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,5 @@ export const wrapContentTypeCollection = wrapCollection(wrapContentType)
367367
export const wrapContentTypeCursorPaginatedCollection: (
368368
makeRequest: MakeRequest,
369369
data: CursorPaginatedCollectionProp<ContentTypeProps>,
370-
) => CursorPaginatedCollectionProp<ContentTypeProps> = wrapCursorPaginatedCollection(
371-
wrapContentType
372-
)
373-
370+
) => CursorPaginatedCollectionProp<ContentTypeProps> =
371+
wrapCursorPaginatedCollection(wrapContentType)

test/integration/asset-integration.test.ts

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,70 +39,72 @@ describe('Asset API - Read', () => {
3939
expect(response.items).toBeTruthy()
4040
})
4141

42-
describe('Gets assets with cursor pagination', () => {
43-
test('gets assets with cursor pagination with items', async () => {
44-
const response = await environment.getAssetsWithCursor()
45-
expect(response.items).toBeTruthy()
46-
})
42+
describe('Gets assets with cursor pagination', () => {
43+
test('gets assets with cursor pagination with items', async () => {
44+
const response = await environment.getAssetsWithCursor()
45+
expect(response.items).toBeTruthy()
46+
})
4747

48-
test('returns a cursor paginated asset collection when no query is provided', async () => {
49-
const response = await environment.getAssetsWithCursor()
48+
test('returns a cursor paginated asset collection when no query is provided', async () => {
49+
const response = await environment.getAssetsWithCursor()
5050

51-
expect(response.items).not.toHaveLength(0)
52-
expect(response.pages).toBeDefined()
53-
expect((response as { total?: number }).total).toBeUndefined()
51+
expect(response.items).not.toHaveLength(0)
52+
expect(response.pages).toBeDefined()
53+
expect((response as { total?: number }).total).toBeUndefined()
5454

55-
response.items.forEach((item) => {
56-
expect(item.sys.type).toEqual('Asset')
57-
expect(item.fields).toBeDefined()
55+
response.items.forEach((item) => {
56+
expect(item.sys.type).toEqual('Asset')
57+
expect(item.fields).toBeDefined()
58+
})
5859
})
59-
})
6060

61-
test('returns [limit] number of items', async () => {
62-
const response = await environment.getAssetsWithCursor({ limit: 3 })
61+
test('returns [limit] number of items', async () => {
62+
const response = await environment.getAssetsWithCursor({ limit: 3 })
6363

64-
expect(response.items).toHaveLength(3)
65-
expect(response.pages).toBeDefined()
66-
expect((response as { total?: number }).total).toBeUndefined()
64+
expect(response.items).toHaveLength(3)
65+
expect(response.pages).toBeDefined()
66+
expect((response as { total?: number }).total).toBeUndefined()
6767

68-
response.items.forEach((item) => {
69-
expect(item.sys.type).toEqual('Asset')
70-
expect(item.fields).toBeDefined()
68+
response.items.forEach((item) => {
69+
expect(item.sys.type).toEqual('Asset')
70+
expect(item.fields).toBeDefined()
71+
})
7172
})
72-
})
7373

74-
test('supports forward pagination', async () => {
75-
const firstPage = await environment.getAssetsWithCursor({ limit: 2 })
76-
const secondPage = await environment.getAssetsWithCursor({
77-
limit: 2,
78-
pageNext: firstPage?.pages?.next,
79-
})
74+
test('supports forward pagination', async () => {
75+
const firstPage = await environment.getAssetsWithCursor({ limit: 2 })
76+
const secondPage = await environment.getAssetsWithCursor({
77+
limit: 2,
78+
pageNext: firstPage?.pages?.next,
79+
})
8080

81-
expect(secondPage.items).toHaveLength(2)
82-
expect(firstPage.items[0].sys.id).not.toEqual(secondPage.items[0].sys.id)
83-
})
81+
expect(secondPage.items).toHaveLength(2)
82+
expect(firstPage.items[0].sys.id).not.toEqual(secondPage.items[0].sys.id)
83+
})
8484

85-
test('should support backward pagination', async () => {
86-
const firstPage = await environment.getAssetsWithCursor({ limit: 2, order: ['sys.createdAt'] })
87-
const secondPage = await environment.getAssetsWithCursor({
88-
limit: 2,
89-
pageNext: firstPage?.pages?.next,
90-
order: ['sys.createdAt'],
91-
})
92-
const result = await environment.getAssetsWithCursor({
93-
limit: 2,
94-
pagePrev: secondPage?.pages?.prev,
95-
order: ['sys.createdAt'],
96-
})
85+
test('should support backward pagination', async () => {
86+
const firstPage = await environment.getAssetsWithCursor({
87+
limit: 2,
88+
order: ['sys.createdAt'],
89+
})
90+
const secondPage = await environment.getAssetsWithCursor({
91+
limit: 2,
92+
pageNext: firstPage?.pages?.next,
93+
order: ['sys.createdAt'],
94+
})
95+
const result = await environment.getAssetsWithCursor({
96+
limit: 2,
97+
pagePrev: secondPage?.pages?.prev,
98+
order: ['sys.createdAt'],
99+
})
97100

98-
expect(result.items).toHaveLength(2)
101+
expect(result.items).toHaveLength(2)
99102

100-
firstPage.items.forEach((item, index) => {
101-
expect(item.sys.id).equal(result.items[index].sys.id)
102-
})
103+
firstPage.items.forEach((item, index) => {
104+
expect(item.sys.id).equal(result.items[index].sys.id)
103105
})
104-
})
105-
106+
})
107+
})
106108

107109
test('Gets published assets', async () => {
108110
const response = await environment.getPublishedAssets()

test/integration/content-type-integration.test.ts

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -52,76 +52,76 @@ describe('ContentType Api', () => {
5252
expect(response.items).toBeTruthy()
5353
})
5454

55-
describe('Gets content types with cursor pagination', () => {
56-
it('gets content types with cursor pagination with items', async () => {
57-
const response = await readEnvironment.getContentTypesWithCursor()
58-
expect(response.items).toBeTruthy()
59-
})
60-
61-
it('returns a cursor paginated content type collection when no query is provided', async () => {
62-
const response = await readEnvironment.getContentTypesWithCursor()
63-
64-
expect(response.items).not.toHaveLength(0)
65-
expect(response.pages).toBeDefined()
66-
expect((response as { total?: number }).total).toBeUndefined()
55+
describe('Gets content types with cursor pagination', () => {
56+
it('gets content types with cursor pagination with items', async () => {
57+
const response = await readEnvironment.getContentTypesWithCursor()
58+
expect(response.items).toBeTruthy()
59+
})
6760

68-
response.items.forEach((ct) => {
69-
expect(ct.sys.type).toEqual('ContentType')
70-
expect(ct.name).toBeDefined()
71-
expect(ct.fields).toBeDefined()
72-
expect(Array.isArray(ct.fields)).toBe(true)
73-
})
74-
})
61+
it('returns a cursor paginated content type collection when no query is provided', async () => {
62+
const response = await readEnvironment.getContentTypesWithCursor()
7563

76-
it('returns [limit] number of items', async () => {
77-
const response = await readEnvironment.getContentTypesWithCursor({ limit: 3 })
64+
expect(response.items).not.toHaveLength(0)
65+
expect(response.pages).toBeDefined()
66+
expect((response as { total?: number }).total).toBeUndefined()
7867

79-
expect(response.items).toHaveLength(3)
80-
expect(response.pages).toBeDefined()
81-
expect((response as { total?: number }).total).toBeUndefined()
68+
response.items.forEach((ct) => {
69+
expect(ct.sys.type).toEqual('ContentType')
70+
expect(ct.name).toBeDefined()
71+
expect(ct.fields).toBeDefined()
72+
expect(Array.isArray(ct.fields)).toBe(true)
73+
})
74+
})
8275

83-
response.items.forEach((ct) => {
84-
expect(ct.sys.type).toEqual('ContentType')
85-
expect(ct.name).toBeDefined()
86-
expect(Array.isArray(ct.fields)).toBe(true)
87-
})
88-
})
76+
it('returns [limit] number of items', async () => {
77+
const response = await readEnvironment.getContentTypesWithCursor({ limit: 3 })
8978

90-
it('supports forward pagination', async () => {
91-
const firstPage = await readEnvironment.getContentTypesWithCursor({ limit: 2 })
92-
const secondPage = await readEnvironment.getContentTypesWithCursor({
93-
limit: 2,
94-
pageNext: firstPage?.pages?.next,
95-
})
79+
expect(response.items).toHaveLength(3)
80+
expect(response.pages).toBeDefined()
81+
expect((response as { total?: number }).total).toBeUndefined()
9682

97-
expect(secondPage.items).toHaveLength(2)
98-
expect(firstPage.items[0].sys.id).not.toEqual(secondPage.items[0].sys.id)
99-
})
83+
response.items.forEach((ct) => {
84+
expect(ct.sys.type).toEqual('ContentType')
85+
expect(ct.name).toBeDefined()
86+
expect(Array.isArray(ct.fields)).toBe(true)
87+
})
88+
})
10089

101-
it('should support backward pagination', async () => {
102-
const firstPage = await readEnvironment.getContentTypesWithCursor({ limit: 2, order: ['sys.createdAt'] })
103-
const secondPage = await readEnvironment.getContentTypesWithCursor({
104-
limit: 2,
105-
pageNext: firstPage?.pages?.next,
106-
order: ['sys.createdAt'],
107-
})
108-
const result = await readEnvironment.getContentTypesWithCursor({
109-
limit: 2,
110-
pagePrev: secondPage?.pages?.prev,
111-
order: ['sys.createdAt'],
112-
})
90+
it('supports forward pagination', async () => {
91+
const firstPage = await readEnvironment.getContentTypesWithCursor({ limit: 2 })
92+
const secondPage = await readEnvironment.getContentTypesWithCursor({
93+
limit: 2,
94+
pageNext: firstPage?.pages?.next,
95+
})
11396

114-
expect(result.items).toHaveLength(2)
97+
expect(secondPage.items).toHaveLength(2)
98+
expect(firstPage.items[0].sys.id).not.toEqual(secondPage.items[0].sys.id)
99+
})
115100

116-
firstPage.items.forEach((item, index) => {
117-
expect(item.sys.id).toEqual(result.items[index].sys.id)
101+
it('should support backward pagination', async () => {
102+
const firstPage = await readEnvironment.getContentTypesWithCursor({
103+
limit: 2,
104+
order: ['sys.createdAt'],
105+
})
106+
const secondPage = await readEnvironment.getContentTypesWithCursor({
107+
limit: 2,
108+
pageNext: firstPage?.pages?.next,
109+
order: ['sys.createdAt'],
110+
})
111+
const result = await readEnvironment.getContentTypesWithCursor({
112+
limit: 2,
113+
pagePrev: secondPage?.pages?.prev,
114+
order: ['sys.createdAt'],
115+
})
116+
117+
expect(result.items).toHaveLength(2)
118+
119+
firstPage.items.forEach((item, index) => {
120+
expect(item.sys.id).toEqual(result.items[index].sys.id)
121+
})
122+
})
118123
})
119124
})
120-
})
121-
122-
123-
124-
})
125125

126126
describe('write', () => {
127127
it('Create, update, publish, getEditorInterface, unpublish and delete content type', async () => {

0 commit comments

Comments
 (0)