|
1 |
| -import '../../../test/test_helper'; |
2 |
| - |
3 | 1 | import querystring from 'querystring';
|
4 | 2 | import http from 'http';
|
5 | 3 |
|
@@ -94,7 +92,13 @@ describe('beginAuth', () => {
|
94 | 92 | });
|
95 | 93 |
|
96 | 94 | test('returns the correct auth url for given info', async () => {
|
97 |
| - const authRoute = await ShopifyOAuth.beginAuth(req, res, shop, '/some-callback', false); |
| 95 | + const authRoute = await ShopifyOAuth.beginAuth( |
| 96 | + req, |
| 97 | + res, |
| 98 | + shop, |
| 99 | + '/some-callback', |
| 100 | + false, |
| 101 | + ); |
98 | 102 | const session = await Context.SESSION_STORAGE.loadSession(cookies.id);
|
99 | 103 | /* eslint-disable @typescript-eslint/naming-convention */
|
100 | 104 | const query = {
|
@@ -170,7 +174,7 @@ describe('validateAuthCallback', () => {
|
170 | 174 | res = {} as http.ServerResponse;
|
171 | 175 |
|
172 | 176 | Cookies.prototype.set.mockImplementation(
|
173 |
| - (cookieName: string, cookieValue: string, options: {expires: Date;}) => { |
| 177 | + (cookieName: string, cookieValue: string, options: {expires: Date}) => { |
174 | 178 | expect(cookieName).toBe('shopify_app_session');
|
175 | 179 | cookies.id = cookieValue;
|
176 | 180 | cookies.expires = options.expires;
|
@@ -383,7 +387,11 @@ describe('validateAuthCallback', () => {
|
383 | 387 | testCallbackQuery.hmac = expectedHmac;
|
384 | 388 |
|
385 | 389 | fetchMock.mockResponse(JSON.stringify(successResponse));
|
386 |
| - const returnedSession = await ShopifyOAuth.validateAuthCallback(req, res, testCallbackQuery); |
| 390 | + const returnedSession = await ShopifyOAuth.validateAuthCallback( |
| 391 | + req, |
| 392 | + res, |
| 393 | + testCallbackQuery, |
| 394 | + ); |
387 | 395 |
|
388 | 396 | const jwtPayload: JwtPayload = {
|
389 | 397 | iss: `https://${shop}/admin`,
|
@@ -425,7 +433,10 @@ describe('validateAuthCallback', () => {
|
425 | 433 | const currentSession = await loadCurrentSession(jwtReq, jwtRes);
|
426 | 434 | expect(currentSession).not.toBe(null);
|
427 | 435 | expect(currentSession?.id).toEqual(jwtSessionId);
|
428 |
| - expect(cookies?.expires?.getTime() as number).toBeWithinSecondsOf(new Date().getTime(), 1); |
| 436 | + expect(cookies?.expires?.getTime() as number).toBeWithinSecondsOf( |
| 437 | + new Date().getTime(), |
| 438 | + 1, |
| 439 | + ); |
429 | 440 | });
|
430 | 441 |
|
431 | 442 | test('properly updates the Oauth cookie for online, non-embedded apps', async () => {
|
@@ -463,11 +474,21 @@ describe('validateAuthCallback', () => {
|
463 | 474 | testCallbackQuery.hmac = expectedHmac;
|
464 | 475 |
|
465 | 476 | fetchMock.mockResponse(JSON.stringify(successResponse));
|
466 |
| - const returnedSession = await ShopifyOAuth.validateAuthCallback(req, res, testCallbackQuery); |
| 477 | + const returnedSession = await ShopifyOAuth.validateAuthCallback( |
| 478 | + req, |
| 479 | + res, |
| 480 | + testCallbackQuery, |
| 481 | + ); |
467 | 482 | expect(returnedSession.id).toEqual(cookies.id);
|
468 | 483 |
|
469 |
| - expect(returnedSession?.expires?.getTime() as number).toBeWithinSecondsOf(new Date(Date.now() + successResponse.expires_in * 1000).getTime(), 1); |
470 |
| - expect(cookies?.expires?.getTime() as number).toBeWithinSecondsOf(returnedSession?.expires?.getTime() as number, 1); |
| 484 | + expect(returnedSession?.expires?.getTime() as number).toBeWithinSecondsOf( |
| 485 | + new Date(Date.now() + successResponse.expires_in * 1000).getTime(), |
| 486 | + 1, |
| 487 | + ); |
| 488 | + expect(cookies?.expires?.getTime() as number).toBeWithinSecondsOf( |
| 489 | + returnedSession?.expires?.getTime() as number, |
| 490 | + 1, |
| 491 | + ); |
471 | 492 |
|
472 | 493 | const cookieSession = await Context.SESSION_STORAGE.loadSession(cookies.id);
|
473 | 494 | expect(cookieSession).not.toBeUndefined();
|
@@ -508,13 +529,20 @@ describe('validateAuthCallback', () => {
|
508 | 529 | testCallbackQuery.hmac = expectedHmac;
|
509 | 530 |
|
510 | 531 | fetchMock.mockResponse(JSON.stringify(successResponse));
|
511 |
| - const returnedSession = await ShopifyOAuth.validateAuthCallback(req, res, testCallbackQuery); |
| 532 | + const returnedSession = await ShopifyOAuth.validateAuthCallback( |
| 533 | + req, |
| 534 | + res, |
| 535 | + testCallbackQuery, |
| 536 | + ); |
512 | 537 | expect(returnedSession.id).toEqual(cookies.id);
|
513 | 538 | expect(returnedSession.id).toEqual(ShopifyOAuth.getOfflineSessionId(shop));
|
514 | 539 |
|
515 | 540 | const cookieSession = await Context.SESSION_STORAGE.loadSession(cookies.id);
|
516 | 541 | expect(cookieSession).not.toBeUndefined();
|
517 |
| - expect(cookies?.expires?.getTime() as number).toBeWithinSecondsOf(new Date().getTime(), 1); |
| 542 | + expect(cookies?.expires?.getTime() as number).toBeWithinSecondsOf( |
| 543 | + new Date().getTime(), |
| 544 | + 1, |
| 545 | + ); |
518 | 546 | expect(returnedSession?.expires?.getTime()).toBeUndefined();
|
519 | 547 | });
|
520 | 548 |
|
@@ -553,7 +581,11 @@ describe('validateAuthCallback', () => {
|
553 | 581 | testCallbackQuery.hmac = expectedHmac;
|
554 | 582 |
|
555 | 583 | fetchMock.mockResponse(JSON.stringify(successResponse));
|
556 |
| - const returnedSession = await ShopifyOAuth.validateAuthCallback(req, res, testCallbackQuery); |
| 584 | + const returnedSession = await ShopifyOAuth.validateAuthCallback( |
| 585 | + req, |
| 586 | + res, |
| 587 | + testCallbackQuery, |
| 588 | + ); |
557 | 589 | expect(returnedSession.id).toEqual(cookies.id);
|
558 | 590 | expect(returnedSession.id).toEqual(ShopifyOAuth.getOfflineSessionId(shop));
|
559 | 591 | expect(cookies?.expires?.getTime()).toBeUndefined();
|
|
0 commit comments