Skip to content

Commit

Permalink
All tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
han-so1omon committed Sep 22, 2024
1 parent be676c9 commit bfdd955
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/__tests__/integration/oauth.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Koa from 'koa';
import bodyParser from '@koa/bodyparser';
import Router from '@koa/router';
import request from 'supertest';
import jwt from 'jsonwebtoken';
Expand Down Expand Up @@ -119,6 +120,15 @@ describe('OAuth integration tests', () => {
router.get('/installed', shopify.ensureInstalledOnShop(), installedMock);
router.get('/authed', shopify.validateAuthenticatedSession(), authedMock);

app.use(bodyParser({
enableTypes: ['json', 'text'], // Enable both JSON and text parsing
encoding: 'utf-8',
jsonLimit: '1mb', // Adjust the limit as needed
textLimit: '1mb',
extendTypes: {
text: ['text/plain'], // Only treat text/plain as text
},
}));
app.use(router.routes()).use(router.allowedMethods());

const callbackInfo = await beginOAuth(app, shopify, config);
Expand Down Expand Up @@ -370,6 +380,7 @@ async function webhookProcessRequest(
) {
await request(app.callback())
.post('/test/webhooks')
.set('Content-Type', 'application/json') // Ensure this header is set
.set(validWebhookHeaders(topic, body, shopify.api.config.apiSecretKey))
.send(body)
.expect(200);
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/integration/webhooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Koa from 'koa';
import bodyParser from '@koa/bodyparser';
import Router from '@koa/router';
import request from 'supertest';
import {LATEST_API_VERSION, LogSeverity} from '@shopify/shopify-api';
Expand Down Expand Up @@ -71,6 +72,15 @@ describe('webhook integration', () => {
...shopify.processWebhooks({webhookHandlers: {APP_UNINSTALLED: config.handler}})
);

app.use(bodyParser({
enableTypes: ['json', 'text'], // Enable both JSON and text parsing
encoding: 'utf-8',
jsonLimit: '1mb', // Adjust the limit as needed
textLimit: '1mb',
extendTypes: {
text: ['text/plain'], // Only treat text/plain as text
},
}));
app.use(router.routes()).use(router.allowedMethods());
});

Expand Down Expand Up @@ -194,6 +204,7 @@ async function triggerWebhook(app: Koa) {

await request(app.callback())
.post('/test/webhooks')
.set('Content-Type', 'application/json') // Ensure this header is set
.set(
validWebhookHeaders(
'APP_UNINSTALLED',
Expand Down
4 changes: 3 additions & 1 deletion src/webhooks/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ export async function process({
config,
}: WebhookProcessParams): Promise<void> {
try {
const isJson = ctx.request.is('application/json');
const rawBody = isJson ? JSON.stringify(ctx.request.body) : ctx.request.body;
await api.webhooks.process({
rawBody: ctx.request.body,
rawBody: rawBody,
rawRequest: ctx.req, // Koa's raw Node.js request object
rawResponse: ctx.res, // Koa's raw Node.js response object
});
Expand Down

0 comments on commit bfdd955

Please sign in to comment.