Skip to content

Commit 82701be

Browse files
committed
fix: refactor batchResolver tests to use dynamic throwOnError flag
1 parent 75684b7 commit 82701be

File tree

1 file changed

+53
-77
lines changed

1 file changed

+53
-77
lines changed

packages/event-handler/tests/unit/appsync-graphql/AppSyncGraphQLResolver.test.ts

Lines changed: 53 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -307,89 +307,65 @@ describe('Class: AppSyncGraphQLResolver', () => {
307307
]);
308308
});
309309

310-
it('preserves the scope when using `batchResolver` decorator when aggregate=false and throwOnError=true', async () => {
311-
// Prepare
312-
const app = new AppSyncGraphQLResolver({ logger: console });
313-
314-
class Lambda {
315-
public scope = 'scoped';
310+
it.each([
311+
{
312+
throwOnError: true,
313+
description: 'throwOnError=true',
314+
},
315+
{
316+
throwOnError: false,
317+
description: 'throwOnError=false',
318+
},
319+
])(
320+
'preserves the scope when using `batchResolver` decorator when aggregate=false and $description',
321+
async ({ throwOnError }) => {
322+
// Prepare
323+
const app = new AppSyncGraphQLResolver({ logger: console });
316324

317-
@app.batchResolver({
318-
fieldName: 'batchGet',
319-
throwOnError: true,
320-
aggregate: false,
321-
})
322-
public async handleBatchGet({ id }: { id: string }) {
323-
return {
324-
id,
325-
scope: `${this.scope} id=${id} throwOnError=true aggregate=false`,
326-
};
327-
}
325+
class Lambda {
326+
public scope = 'scoped';
327+
328+
@app.batchResolver({
329+
fieldName: 'batchGet',
330+
throwOnError,
331+
aggregate: false,
332+
})
333+
public async handleBatchGet({ id }: { id: string }) {
334+
return {
335+
id,
336+
scope: `${this.scope} id=${id} throwOnError=${throwOnError} aggregate=false`,
337+
};
338+
}
328339

329-
public async handler(event: unknown, context: Context) {
330-
return app.resolve(event, context, { scope: this });
340+
public async handler(event: unknown, context: Context) {
341+
return app.resolve(event, context, { scope: this });
342+
}
331343
}
332-
}
333-
const lambda = new Lambda();
334-
const handler = lambda.handler.bind(lambda);
335-
336-
// Act
337-
const result = await handler(
338-
[
339-
onGraphqlEventFactory('batchGet', 'Query', { id: 1 }),
340-
onGraphqlEventFactory('batchGet', 'Query', { id: 2 }),
341-
],
342-
context
343-
);
344-
345-
// Assess
346-
expect(result).toEqual([
347-
{ id: 1, scope: 'scoped id=1 throwOnError=true aggregate=false' },
348-
{ id: 2, scope: 'scoped id=2 throwOnError=true aggregate=false' },
349-
]);
350-
});
344+
const lambda = new Lambda();
345+
const handler = lambda.handler.bind(lambda);
351346

352-
it('preserves the scope when using `batchResolver` decorator when aggregate=false and throwOnError=false', async () => {
353-
// Prepare
354-
const app = new AppSyncGraphQLResolver({ logger: console });
355-
356-
class Lambda {
357-
public scope = 'scoped';
358-
359-
@app.batchResolver({
360-
fieldName: 'batchGet',
361-
throwOnError: false,
362-
aggregate: false,
363-
})
364-
public async handleBatchGet({ id }: { id: string }) {
365-
return {
366-
id,
367-
scope: `${this.scope} id=${id} throwOnError=false aggregate=false`,
368-
};
369-
}
347+
// Act
348+
const result = await handler(
349+
[
350+
onGraphqlEventFactory('batchGet', 'Query', { id: 1 }),
351+
onGraphqlEventFactory('batchGet', 'Query', { id: 2 }),
352+
],
353+
context
354+
);
370355

371-
public async handler(event: unknown, context: Context) {
372-
return app.resolve(event, context, { scope: this });
373-
}
356+
// Assess
357+
expect(result).toEqual([
358+
{
359+
id: 1,
360+
scope: `scoped id=1 throwOnError=${throwOnError} aggregate=false`,
361+
},
362+
{
363+
id: 2,
364+
scope: `scoped id=2 throwOnError=${throwOnError} aggregate=false`,
365+
},
366+
]);
374367
}
375-
const lambda = new Lambda();
376-
const handler = lambda.handler.bind(lambda);
377-
378-
// Act
379-
const result = await handler(
380-
[
381-
onGraphqlEventFactory('batchGet', 'Query', { id: 1 }),
382-
onGraphqlEventFactory('batchGet', 'Query', { id: 2 }),
383-
],
384-
context
385-
);
386-
387-
// Assess
388-
expect(result).toEqual([
389-
{ id: 1, scope: 'scoped id=1 throwOnError=false aggregate=false' },
390-
{ id: 2, scope: 'scoped id=2 throwOnError=false aggregate=false' },
391-
]);
392-
});
368+
);
393369

394370
it('emits debug message when AWS_LAMBDA_LOG_LEVEL is set to DEBUG', async () => {
395371
// Prepare

0 commit comments

Comments
 (0)