-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into nv-5432-fix-typeerror-related-to-subscriberi…
…dtrim-function
- Loading branch information
Showing
444 changed files
with
8,863 additions
and
3,629 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
"EQAs", | ||
"analagous", | ||
"addrs", | ||
"Tiering", | ||
"subscriberpayloaddto", | ||
"adresses", | ||
"APIJSON", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Submodule .source
updated
from b984c9 to b6b5ad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ GLOBAL_CONTEXT_PATH= | |
API_CONTEXT_PATH= | ||
DISABLE_USER_REGISTRATION=false | ||
|
||
NEST_STARTER_MAIL=[email protected] | ||
CLIENT_SUCCESS_AUTH_REDIRECT=https://dashboard.novu-staging.co/auth/login | ||
|
||
REDIS_PORT=6379 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ API_CONTEXT_PATH= | |
DISABLE_USER_REGISTRATION=false | ||
|
||
WIDGET_BASE_URL=https://widget.novu.co | ||
NEST_STARTER_MAIL=[email protected] | ||
|
||
REDIS_PORT=6379 | ||
REDIS_PREFIX= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* eslint-disable global-require */ | ||
import { Test } from '@nestjs/testing'; | ||
import { expect } from 'chai'; | ||
import { EnvironmentRepository } from '@novu/dal'; | ||
import sinon from 'sinon'; | ||
import { ApiAuthSchemeEnum, UserSessionData } from '@novu/shared'; | ||
import { HttpRequestHeaderKeysEnum } from '@novu/application-generic'; | ||
import { UnauthorizedException } from '@nestjs/common'; | ||
|
||
describe('ClerkStrategy', () => { | ||
let eeAuth: any; | ||
|
||
try { | ||
eeAuth = require('@novu/ee-auth'); | ||
} catch (error) { | ||
return; | ||
} | ||
|
||
const { ClerkStrategy, LinkEntitiesService, ClerkJwtPayload } = eeAuth; | ||
|
||
let strategy: typeof ClerkStrategy; | ||
let mockEnvironmentRepository: { findOne: sinon.SinonStub }; | ||
let mockLinkEntitiesService: { linkInternalExternalEntities: sinon.SinonStub }; | ||
|
||
const mockRequest = { | ||
headers: { | ||
[HttpRequestHeaderKeysEnum.NOVU_ENVIRONMENT_ID.toLowerCase()]: 'env-123', | ||
}, | ||
}; | ||
|
||
const mockPayload: Partial<typeof ClerkJwtPayload> = { | ||
_id: 'clerk-user-123', | ||
org_id: 'clerk-org-123', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
profilePicture: 'https://example.com/profile.png', | ||
email: '[email protected]', | ||
org_role: 'org:admin', | ||
externalId: undefined, | ||
externalOrgId: undefined, | ||
}; | ||
|
||
beforeEach(async () => { | ||
mockEnvironmentRepository = { | ||
findOne: sinon.stub().resolves({ _id: 'env-123' }), | ||
}; | ||
|
||
mockLinkEntitiesService = { | ||
linkInternalExternalEntities: sinon.stub().resolves({ | ||
internalUserId: 'internal-user-123', | ||
internalOrgId: 'internal-org-123', | ||
}), | ||
}; | ||
|
||
const moduleRef = await Test.createTestingModule({ | ||
providers: [ | ||
ClerkStrategy, | ||
{ provide: EnvironmentRepository, useValue: mockEnvironmentRepository }, | ||
{ provide: LinkEntitiesService, useValue: mockLinkEntitiesService }, | ||
], | ||
}).compile(); | ||
|
||
strategy = moduleRef.get<typeof ClerkStrategy>(ClerkStrategy); | ||
}); | ||
|
||
describe('validate', () => { | ||
it('should transform Clerk payload into valid user session', async () => { | ||
const result: UserSessionData = await strategy.validate(mockRequest, mockPayload); | ||
|
||
expect(result).to.deep.include({ | ||
_id: 'internal-user-123', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
organizationId: 'internal-org-123', | ||
roles: ['admin'], | ||
environmentId: 'env-123', | ||
scheme: ApiAuthSchemeEnum.BEARER, | ||
}); | ||
}); | ||
|
||
it('should call linkInternalExternalEntities with correct parameters', async () => { | ||
await strategy.validate(mockRequest, mockPayload); | ||
|
||
expect(mockLinkEntitiesService.linkInternalExternalEntities.calledOnceWith(mockRequest, mockPayload)).to.be.true; | ||
}); | ||
|
||
it('should verify environment access', async () => { | ||
await strategy.validate(mockRequest, mockPayload); | ||
|
||
expect( | ||
mockEnvironmentRepository.findOne.calledOnceWith( | ||
{ | ||
_id: 'env-123', | ||
_organizationId: 'internal-org-123', | ||
}, | ||
'_id' | ||
) | ||
).to.be.true; | ||
}); | ||
|
||
it('should throw UnauthorizedException when environment is not found', async () => { | ||
mockEnvironmentRepository.findOne.resolves(null); | ||
|
||
try { | ||
await strategy.validate(mockRequest, mockPayload); | ||
expect.fail('Should have thrown an error'); | ||
} catch (err) { | ||
expect(err).to.be.instanceOf(UnauthorizedException); | ||
expect(err.message).to.equal('Cannot find environment'); | ||
} | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.