Skip to content

Commit 291e248

Browse files
committed
added lots of testing
1 parent 0be620a commit 291e248

2 files changed

Lines changed: 198 additions & 2 deletions

File tree

__tests__/__snapshots__/resolvers.test.js.snap

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exports[`dynamodb resolvers something 2`] = `
3838
]
3939
`;
4040

41-
exports[`rds resolvers attributeExists 1`] = `
41+
exports[`rds resolvers attributeExists nested or 1`] = `
4242
{
4343
"statements": [
4444
"SELECT * FROM "supplier" WHERE "id" = :P0 AND (("deleted" = :P1) OR ("deleted" IS NULL))",
@@ -51,6 +51,16 @@ exports[`rds resolvers attributeExists 1`] = `
5151
}
5252
`;
5353

54+
exports[`rds resolvers attributeExists true false 1`] = `
55+
{
56+
"statements": [
57+
"SELECT * FROM "supplier" WHERE "created" IS NOT NULL AND "deleted" IS NULL",
58+
],
59+
"variableMap": {},
60+
"variableTypeHintMap": {},
61+
}
62+
`;
63+
5464
exports[`rds resolvers mysql insert 1`] = `
5565
{
5666
"statements": [
@@ -375,3 +385,73 @@ exports[`rds resolvers typehints UUID 1`] = `
375385
"value": "abc123",
376386
}
377387
`;
388+
389+
exports[`rds resolvers where mixed inline and 1`] = `
390+
{
391+
"statements": [
392+
"SELECT * FROM "supplier" WHERE "count" <= :P0 AND ("id" = :P1) AND "deleted" IS NULL",
393+
],
394+
"variableMap": {
395+
":P0": 10,
396+
":P1": 123456,
397+
},
398+
"variableTypeHintMap": {},
399+
}
400+
`;
401+
402+
exports[`rds resolvers where mixed or/and 1`] = `
403+
{
404+
"statements": [
405+
"SELECT * FROM "supplier" WHERE ("id" = :P0) AND ("id" = :P1) AND "id" = :P2",
406+
],
407+
"variableMap": {
408+
":P0": "and eq",
409+
":P1": "or eq 2",
410+
":P2": "id eq",
411+
},
412+
"variableTypeHintMap": {},
413+
}
414+
`;
415+
416+
exports[`rds resolvers where mixed or/and multiple or 1`] = `
417+
{
418+
"statements": [
419+
"SELECT * FROM "supplier" WHERE ("id" = :P0) AND ("id" = :P1) OR ("id" = :P2) AND "id" = :P3",
420+
],
421+
"variableMap": {
422+
":P0": "and eq",
423+
":P1": "or eq 1",
424+
":P2": "or eq 2",
425+
":P3": "id eq",
426+
},
427+
"variableTypeHintMap": {},
428+
}
429+
`;
430+
431+
exports[`rds resolvers where nested ors with ands 1`] = `
432+
{
433+
"statements": [
434+
"SELECT * FROM "supplier" WHERE "id" = :P0 AND ("id" = :P1) OR (("id" = :P2) OR ("id" = :P3)) OR ("id" = :P4)",
435+
],
436+
"variableMap": {
437+
":P0": "id eq",
438+
":P1": "or 1",
439+
":P2": "or nested 1",
440+
":P3": "or nested 2",
441+
":P4": "final or",
442+
},
443+
"variableTypeHintMap": {},
444+
}
445+
`;
446+
447+
exports[`rds resolvers where single value in and 1`] = `
448+
{
449+
"statements": [
450+
"SELECT * FROM "supplier" WHERE ("id" = :P0)",
451+
],
452+
"variableMap": {
453+
":P0": 123456,
454+
},
455+
"variableTypeHintMap": {},
456+
}
457+
`;

__tests__/resolvers.test.js

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,123 @@ describe("rds resolvers", () => {
503503
await checkResolverValid(code, responseContext, "response");
504504
})
505505

506-
test("attributeExists", async () => {
506+
test("where mixed inline and", async () => {
507+
const code = `
508+
export function request(ctx) {
509+
const query = rds.select({
510+
table: 'supplier',
511+
where: {
512+
count: { le: 10 },
513+
and: [{ id: { eq: 123456 } }],
514+
deleted: { attributeExists: false }
515+
}
516+
});
517+
return rds.createPgStatement(query);
518+
}
519+
export function response(ctx) {}
520+
`;
521+
await checkResolverValid(code, {}, "request");
522+
})
523+
524+
test("where single value in and", async () => {
525+
const code = `
526+
export function request(ctx) {
527+
const query = rds.select({
528+
table: 'supplier',
529+
where: {
530+
and: [{ id: { eq: 123456 } }],
531+
}
532+
});
533+
return rds.createPgStatement(query);
534+
}
535+
export function response(ctx) {}
536+
`;
537+
await checkResolverValid(code, {}, "request");
538+
})
539+
540+
test("where mixed or/and", async () => {
541+
const code = `
542+
export function request(ctx) {
543+
const query = rds.select({
544+
table: 'supplier',
545+
where: {
546+
and: [{ id: { eq: "and eq" } }],
547+
or: [{ id: { eq: "or eq 2" } }],
548+
id: { eq: "id eq" },
549+
}
550+
});
551+
return rds.createPgStatement(query);
552+
}
553+
export function response(ctx) {}
554+
`;
555+
await checkResolverValid(code, {}, "request");
556+
})
557+
558+
test("where mixed or/and multiple or", async () => {
559+
const code = `
560+
export function request(ctx) {
561+
const query = rds.select({
562+
table: 'supplier',
563+
where: {
564+
and: [{ id: { eq: "and eq" } }],
565+
or: [
566+
{ id: { eq: "or eq 1" } },
567+
{ id: { eq: "or eq 2" } }
568+
],
569+
id: { eq: "id eq" },
570+
}
571+
});
572+
return rds.createPgStatement(query);
573+
}
574+
export function response(ctx) {}
575+
`;
576+
await checkResolverValid(code, {}, "request");
577+
})
578+
579+
test("where nested ors with ands", async () => {
580+
const code = `
581+
export function request(ctx) {
582+
const query = rds.select({
583+
table: 'supplier',
584+
where: {
585+
id: { eq: "id eq" },
586+
or: [
587+
{ id: { eq: "or 1" } },
588+
{
589+
or: [
590+
{ id: { eq: "or nested 1" } },
591+
{ id: { eq: "or nested 2" } }
592+
]
593+
},
594+
{ id: { eq: "final or" } }
595+
]
596+
}
597+
});
598+
return rds.createPgStatement(query);
599+
}
600+
export function response(ctx) {}
601+
`;
602+
await checkResolverValid(code, {}, "request");
603+
})
604+
605+
test("attributeExists true false", async () => {
606+
const code = `
607+
export function request(ctx) {
608+
const query = rds.select({
609+
table: 'supplier',
610+
where: {
611+
created: { attributeExists: true },
612+
deleted: { attributeExists: false }
613+
}
614+
});
615+
return rds.createPgStatement(query);
616+
}
617+
export function response(ctx) {}
618+
`;
619+
await checkResolverValid(code, {}, "request");
620+
})
621+
622+
test("attributeExists nested or", async () => {
507623
const code = `
508624
export function request(ctx) {
509625
const query = rds.select({

0 commit comments

Comments
 (0)