mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(appsync): respect string normalization form (#7284)
This commit is contained in:
1 parent
4438e3df49
commit
a15fb6b331
2 files changed
+33
-1
No files matched your search
@@ -182,7 +182,9 @@ export const util = {
|
||||
toElasticsearchQueryDSL: unsupported('transform.toElasticsearchQueryDSL')
|
||||
},
|
||||
str: {
|
||||
normalize: (v) => String(v).normalize(),
|
||||
normalize: (v, form) => String(v).normalize(
|
||||
form === undefined ? 'NFC' : String(form).toUpperCase()
|
||||
),
|
||||
toUpper: (v) => String(v).toUpperCase(),
|
||||
toLower: (v) => String(v).toLowerCase()
|
||||
}
|
||||
|
||||
+30
@@ -53,6 +53,7 @@ class AppSyncJsResolverDockerIntegrationTest {
|
||||
importsNode: String
|
||||
loops: String
|
||||
keywordsInText: String
|
||||
normalizeString: String
|
||||
}
|
||||
""";
|
||||
|
||||
@@ -172,6 +173,23 @@ class AppSyncJsResolverDockerIntegrationTest {
|
||||
|
||||
private String apiId;
|
||||
private String apiKey;
|
||||
private static final String NORMALIZE_STRING_RESOLVER = """
|
||||
import { util } from "@aws-appsync/utils";
|
||||
export function request(ctx) {
|
||||
const value = "\\u00E9";
|
||||
return { payload: {
|
||||
defaultForm: util.str.normalize(value),
|
||||
nfc: util.str.normalize(value, "NFC"),
|
||||
nfd: util.str.normalize(value, "NFD"),
|
||||
nfkc: util.str.normalize(value, "NFKC"),
|
||||
nfkd: util.str.normalize(value, "NFKD"),
|
||||
lowercaseNfkd: util.str.normalize(value, "nfkd")
|
||||
} };
|
||||
}
|
||||
export function response(ctx) {
|
||||
return JSON.stringify(ctx.result);
|
||||
}
|
||||
""";
|
||||
|
||||
@BeforeAll
|
||||
static void configure() {
|
||||
@@ -197,6 +215,7 @@ class AppSyncJsResolverDockerIntegrationTest {
|
||||
createUnitResolver(apiId, "Query", "importsNode", "local", NODE_IMPORT_RESOLVER);
|
||||
createUnitResolver(apiId, "Query", "loops", "local", WHILE_RESOLVER);
|
||||
createUnitResolver(apiId, "Query", "keywordsInText", "local", KEYWORDS_IN_TEXT_RESOLVER);
|
||||
createUnitResolver(apiId, "Query", "normalizeString", "local", NORMALIZE_STRING_RESOLVER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -264,6 +283,17 @@ class AppSyncJsResolverDockerIntegrationTest {
|
||||
.body("data.ping", equalTo("pong"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void utilStrNormalizeRespectsTheRequestedFormAndDefaultsToNfc() {
|
||||
query("{ normalizeString }")
|
||||
.statusCode(200)
|
||||
.body("errors", nullValue())
|
||||
.body("data.normalizeString", equalTo(
|
||||
"{\"defaultForm\":\"é\",\"nfc\":\"é\",\"nfd\":\"é\","
|
||||
+ "\"nfkc\":\"é\",\"nfkd\":\"é\",\"lowercaseNfkd\":\"é\"}"
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anExplicitNullArgumentReachesTheResolverInsteadOfFailingTheBatch() {
|
||||
// nextToken: null is ordinary GraphQL, and an explicit null is not the same as an absent
|
||||
|
||||
Reference in new issue
Block a user