From b0f8c01ec073231c1baa2c98f6480573ff9051b3 Mon Sep 17 00:00:00 2001 From: Carmela Leung Date: Fri, 9 Apr 2021 14:31:54 -0400 Subject: [PATCH] Add check --- src/auth/scopes/index.ts | 6 ++++++ src/auth/scopes/test/scopes.test.ts | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/auth/scopes/index.ts b/src/auth/scopes/index.ts index 036a8d750..62e74fdaa 100644 --- a/src/auth/scopes/index.ts +++ b/src/auth/scopes/index.ts @@ -1,3 +1,5 @@ +//import {MissingRequiredArgument} from '../../error'; + class AuthScopes { public static SCOPE_DELIMITER = ','; @@ -38,6 +40,10 @@ class AuthScopes { public equals(otherScopes: string | string[] | AuthScopes) { let other: AuthScopes; + // if (!otherScopes) { + // throw new MissingRequiredArgument('Missing scopes'); + // } + if (otherScopes instanceof AuthScopes) { other = otherScopes; } else { diff --git a/src/auth/scopes/test/scopes.test.ts b/src/auth/scopes/test/scopes.test.ts index e44353d8d..34e5dafc9 100644 --- a/src/auth/scopes/test/scopes.test.ts +++ b/src/auth/scopes/test/scopes.test.ts @@ -1,4 +1,5 @@ import '../../../test/test_helper'; +import * as ShopifyErrors from '../../../error'; import {AuthScopes} from '../index'; @@ -65,6 +66,13 @@ describe('AuthScopes.equals', () => { expect(scopes2.equals(scopes1)).toBeFalsy(); }); + it('throws an error if no scopes', () => { + const scopes1 = new AuthScopes('write_customers,read_products'); + const scopes2: string = ''; + + expect(scopes1.equals(scopes2)).toThrow(ShopifyErrors.MissingRequiredArgument); + }) + it('allows comparing against strings', () => { const scopes1 = new AuthScopes('write_customers,read_products,write_products');