From d20c68ba52e28dcdfb4310b46b92f726ab635f6d Mon Sep 17 00:00:00 2001 From: Sweta Barman Date: Tue, 24 Sep 2024 14:12:48 -0400 Subject: [PATCH 1/2] fix: Add a unit test for imports.write_all_domains scope --- .../test/unit/models/api-key.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/spacecat-shared-data-access/test/unit/models/api-key.test.js b/packages/spacecat-shared-data-access/test/unit/models/api-key.test.js index ab54a004..847ab952 100644 --- a/packages/spacecat-shared-data-access/test/unit/models/api-key.test.js +++ b/packages/spacecat-shared-data-access/test/unit/models/api-key.test.js @@ -54,6 +54,11 @@ describe('ApiKey Model tests', () => { expect(apiKey.getCreatedAt()).is.not.empty; }); + it('creates an ApiKey object for a user with scope - imports.write_all_domains', () => { + const apiKey = createApiKey({ ...validApiKey, scopes: [{ name: 'imports.write_all_domains', domains: [] }] }); + expect(apiKey.getScopes()).to.deep.equal([{ name: 'imports.write_all_domains', domains: [] }]); + }); + it('throws an error if revokedAt is not a valid date', () => { expect(() => createApiKey({ ...validApiKey, revokedAt: 'invalid-date' })).to.throw('revokedAt should be a valid ISO 8601 string: invalid-date'); }); From 85f070acdb6971c0a97c66d3a770d663622d944d Mon Sep 17 00:00:00 2001 From: Sweta Barman Date: Wed, 25 Sep 2024 07:45:05 -0400 Subject: [PATCH 2/2] fix: Add an additional unit test for imports.write --- .../test/unit/models/api-key.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/spacecat-shared-data-access/test/unit/models/api-key.test.js b/packages/spacecat-shared-data-access/test/unit/models/api-key.test.js index 847ab952..15e54a1f 100644 --- a/packages/spacecat-shared-data-access/test/unit/models/api-key.test.js +++ b/packages/spacecat-shared-data-access/test/unit/models/api-key.test.js @@ -59,6 +59,11 @@ describe('ApiKey Model tests', () => { expect(apiKey.getScopes()).to.deep.equal([{ name: 'imports.write_all_domains', domains: [] }]); }); + it('creates an ApiKey object for a user with scope - imports.write', () => { + const apiKey = createApiKey({ ...validApiKey, scopes: [{ name: 'imports.write', domains: ['https://adobe.com', 'https://test.com'] }] }); + expect(apiKey.getScopes()).to.deep.equal([{ name: 'imports.write', domains: ['https://adobe.com', 'https://test.com'] }]); + }); + it('throws an error if revokedAt is not a valid date', () => { expect(() => createApiKey({ ...validApiKey, revokedAt: 'invalid-date' })).to.throw('revokedAt should be a valid ISO 8601 string: invalid-date'); });