-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add array support for some methods and fix type quirks
- Loading branch information
1 parent
24f5822
commit 883cbba
Showing
4 changed files
with
112 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'js-craftcms-api': patch | ||
--- | ||
|
||
Add support for arrays in id and section methods. | ||
Remove status method from common builder and add custom status method to entry and user query. | ||
Add Prettify typescript helper. | ||
Fix some quirks in type definitions for the querybuilders. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import { buildCraftQueryUrl } from '../index'; | ||
import { describe, it, expect } from 'vitest'; | ||
import type { ElementType, ExecutionMethods } from '../index'; | ||
import type { ElementType, ExecutionMethod } from '../index'; | ||
|
||
describe('buildCraftQueryUrl Tests', () => { | ||
describe('buildCraftQueryUrl - CommonQueryBuilder', () => { | ||
const arrOfExecutionTypes: ExecutionMethods[] = ['one', 'all']; | ||
const arrOfExecutionTypes: ExecutionMethod[] = ['one', 'all']; | ||
const arrOfElementTypes: ElementType[] = ['addresses', 'assets', 'entries', 'users']; | ||
|
||
arrOfElementTypes.forEach((elementType) => { | ||
const queryBuilder = buildCraftQueryUrl(elementType); | ||
const baseQuery = queryBuilder | ||
.id(1) | ||
.limit(5) | ||
.status('active') | ||
.offset(2) | ||
.orderBy('name') | ||
.fields(['title', 'heroImage']); | ||
|
@@ -22,7 +21,7 @@ describe('buildCraftQueryUrl Tests', () => { | |
const queryUrlOne = baseQuery.buildBaseUrl(executionType); | ||
|
||
expect(queryUrlOne).toContain( | ||
`elementType=${elementType}&id=1&limit=5&status=active&offset=2&orderBy=name&fields=title%2CheroImage&${executionType}=1`, | ||
`elementType=${elementType}&id=1&limit=5&offset=2&orderBy=name&fields=title%2CheroImage&${executionType}=1`, | ||
); | ||
}); | ||
}); | ||
|
@@ -73,10 +72,11 @@ describe('buildCraftQueryUrl Tests', () => { | |
.postDate('2023-01-01') | ||
.site('default') | ||
.siteId(1) | ||
.status('live') | ||
.buildBaseUrl('one'); | ||
|
||
expect(queryUrl).toContain( | ||
'elementType=entries&slug=my-slug&uri=news%2F2023§ion=news&postDate=2023-01-01&site=default&siteId=1&one=1', | ||
'elementType=entries&slug=my-slug&uri=news%2F2023§ion=news&postDate=2023-01-01&site=default&siteId=1&status=live&one=1', | ||
); | ||
}); | ||
}); | ||
|
@@ -90,10 +90,11 @@ describe('buildCraftQueryUrl Tests', () => { | |
.email('[email protected]') | ||
.fullName('superuser') | ||
.hasPhoto(true) | ||
.status('active') | ||
.buildBaseUrl('one'); | ||
|
||
expect(queryUrl).toContain( | ||
'elementType=users&group=admins&groupId=1&email=admin%40test.com&fullName=superuser&hasPhoto=true&one=1', | ||
'elementType=users&group=admins&groupId=1&email=admin%40test.com&fullName=superuser&hasPhoto=true&status=active&one=1', | ||
); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters