-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): added new array-like structure
- Loading branch information
1 parent
4dde834
commit 27c6fc1
Showing
50 changed files
with
1,294 additions
and
1,026 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
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { ConfigModule, MedusaContainer } from '@medusajs/medusa/dist/types/global'; | ||
import { Auth0AdminStrategy } from '../../admin'; | ||
import { AUTH_PROVIDER_KEY } from '../../../../types'; | ||
import { Auth0Options, AUTH0_ADMIN_STRATEGY_NAME, Profile, ExtraParams } from '../../types'; | ||
import { AUTH_PROVIDER_KEY, IStrategy } from '../../../../types'; | ||
import { AUTH0_ADMIN_STRATEGY_NAME, Auth0Options, ExtraParams } from '../../types'; | ||
import { Profile } from 'passport-auth0'; | ||
import { getAuth0AdminStrategy } from '../../admin'; | ||
|
||
describe('Auth0 admin strategy verify callback', function () { | ||
describe('Auth0 admin strategy verify callback', function() { | ||
const existsEmail = '[email protected]'; | ||
const existsEmailWithProviderKey = '[email protected]'; | ||
const existsEmailWithWrongProviderKey = '[email protected]'; | ||
|
@@ -12,9 +13,9 @@ describe('Auth0 admin strategy verify callback', function () { | |
let req: Request; | ||
let accessToken: string; | ||
let refreshToken: string; | ||
let profile: Profile; | ||
let profile: Partial<Profile>; | ||
let extraParams: ExtraParams; | ||
let auth0AdminStrategy: Auth0AdminStrategy; | ||
let auth0AdminStrategy: IStrategy; | ||
|
||
beforeEach(() => { | ||
profile = { | ||
|
@@ -38,7 +39,7 @@ describe('Auth0 admin strategy verify callback', function () { | |
return { | ||
id: 'test2', | ||
metadata: { | ||
[AUTH_PROVIDER_KEY]: AUTH0_ADMIN_STRATEGY_NAME, | ||
[AUTH_PROVIDER_KEY]: AUTH0_ADMIN_STRATEGY_NAME + '_test', | ||
}, | ||
}; | ||
} | ||
|
@@ -62,8 +63,9 @@ describe('Auth0 admin strategy verify callback', function () { | |
} as MedusaContainer; | ||
}); | ||
|
||
describe('when strict is set to admin', function () { | ||
describe('when strict is set to admin', function() { | ||
beforeEach(() => { | ||
const Auth0AdminStrategy = getAuth0AdminStrategy('test'); | ||
auth0AdminStrategy = new Auth0AdminStrategy( | ||
container, | ||
{} as ConfigModule, | ||
|
@@ -73,7 +75,7 @@ describe('Auth0 admin strategy verify callback', function () { | |
clientSecret: 'fake', | ||
admin: { callbackUrl: '/fakeCallbackUrl' }, | ||
} as Auth0Options, | ||
'admin' | ||
'admin', | ||
); | ||
}); | ||
|
||
|
@@ -90,7 +92,7 @@ describe('Auth0 admin strategy verify callback', function () { | |
expect(data).toEqual( | ||
expect.objectContaining({ | ||
id: 'test2', | ||
}) | ||
}), | ||
); | ||
}); | ||
|
||
|
@@ -128,8 +130,9 @@ describe('Auth0 admin strategy verify callback', function () { | |
}); | ||
}); | ||
|
||
describe('when strict is set for store only', function () { | ||
describe('when strict is set for store only', function() { | ||
beforeEach(() => { | ||
const Auth0AdminStrategy = getAuth0AdminStrategy('test'); | ||
auth0AdminStrategy = new Auth0AdminStrategy( | ||
container, | ||
{} as ConfigModule, | ||
|
@@ -139,7 +142,7 @@ describe('Auth0 admin strategy verify callback', function () { | |
clientSecret: 'fake', | ||
admin: { callbackUrl: '/fakeCallbackUrl' }, | ||
} as Auth0Options, | ||
'store' | ||
'store', | ||
); | ||
}); | ||
|
||
|
@@ -156,7 +159,7 @@ describe('Auth0 admin strategy verify callback', function () { | |
expect(data).toEqual( | ||
expect.objectContaining({ | ||
id: 'test2', | ||
}) | ||
}), | ||
); | ||
}); | ||
|
||
|
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { Auth0StoreStrategy } from '../../store'; | ||
import { ConfigModule, MedusaContainer } from '@medusajs/medusa/dist/types/global'; | ||
import { AUTH_PROVIDER_KEY, CUSTOMER_METADATA_KEY } from '../../../../types'; | ||
import { Auth0Options, AUTH0_STORE_STRATEGY_NAME, Profile, ExtraParams } from '../../types'; | ||
import { AUTH_PROVIDER_KEY, CUSTOMER_METADATA_KEY, IStrategy } from '../../../../types'; | ||
import { AUTH0_STORE_STRATEGY_NAME, Auth0Options, ExtraParams } from '../../types'; | ||
import { Profile } from 'passport-auth0'; | ||
import { getAuth0StoreStrategy } from '../../store'; | ||
|
||
describe('Auth0 store strategy verify callback', function () { | ||
describe('Auth0 store strategy verify callback', function() { | ||
const existsEmail = '[email protected]'; | ||
const existsEmailWithMeta = '[email protected]'; | ||
const existsEmailWithMetaAndProviderKey = '[email protected]'; | ||
|
@@ -13,9 +14,9 @@ describe('Auth0 store strategy verify callback', function () { | |
let req: Request; | ||
let accessToken: string; | ||
let refreshToken: string; | ||
let profile: Profile; | ||
let profile: Partial<Profile>; | ||
let extraParams: ExtraParams; | ||
let auth0StoreStrategy: Auth0StoreStrategy; | ||
let auth0StoreStrategy: IStrategy; | ||
let updateFn; | ||
let createFn; | ||
|
||
|
@@ -36,12 +37,12 @@ describe('Auth0 store strategy verify callback', function () { | |
resolve: <T>(name: string): T => { | ||
const container_ = { | ||
manager: { | ||
transaction: function (cb) { | ||
transaction: function(cb) { | ||
return cb(); | ||
}, | ||
}, | ||
customerService: { | ||
withTransaction: function () { | ||
withTransaction: function() { | ||
return this; | ||
}, | ||
create: createFn, | ||
|
@@ -67,7 +68,7 @@ describe('Auth0 store strategy verify callback', function () { | |
id: 'test3', | ||
metadata: { | ||
[CUSTOMER_METADATA_KEY]: true, | ||
[AUTH_PROVIDER_KEY]: AUTH0_STORE_STRATEGY_NAME, | ||
[AUTH_PROVIDER_KEY]: AUTH0_STORE_STRATEGY_NAME + '_test', | ||
}, | ||
}; | ||
} | ||
|
@@ -92,8 +93,9 @@ describe('Auth0 store strategy verify callback', function () { | |
} as MedusaContainer; | ||
}); | ||
|
||
describe('when strict is set to store', function () { | ||
describe('when strict is set to store', function() { | ||
beforeEach(() => { | ||
const Auth0StoreStrategy = getAuth0StoreStrategy('test'); | ||
auth0StoreStrategy = new Auth0StoreStrategy( | ||
container, | ||
{} as ConfigModule, | ||
|
@@ -103,7 +105,7 @@ describe('Auth0 store strategy verify callback', function () { | |
clientSecret: 'fake', | ||
store: { callbackUrl: '/fakeCallbackUrl' }, | ||
} as Auth0Options, | ||
'store' | ||
'store', | ||
); | ||
}); | ||
|
||
|
@@ -120,7 +122,7 @@ describe('Auth0 store strategy verify callback', function () { | |
expect(data).toEqual( | ||
expect.objectContaining({ | ||
id: 'test3', | ||
}) | ||
}), | ||
); | ||
}); | ||
|
||
|
@@ -144,7 +146,7 @@ describe('Auth0 store strategy verify callback', function () { | |
expect(data).toEqual( | ||
expect.objectContaining({ | ||
id: 'test2', | ||
}) | ||
}), | ||
); | ||
expect(updateFn).toHaveBeenCalledTimes(1); | ||
}); | ||
|
@@ -158,7 +160,7 @@ describe('Auth0 store strategy verify callback', function () { | |
.validate(req, accessToken, refreshToken, extraParams, profile) | ||
.catch((err) => err); | ||
expect(err).toEqual( | ||
new Error(`Customer with email ${existsEmailWithMetaButWrongProviderKey} already exists`) | ||
new Error(`Customer with email ${existsEmailWithMetaButWrongProviderKey} already exists`), | ||
); | ||
}); | ||
|
||
|
@@ -175,14 +177,15 @@ describe('Auth0 store strategy verify callback', function () { | |
expect(data).toEqual( | ||
expect.objectContaining({ | ||
id: 'test', | ||
}) | ||
}), | ||
); | ||
expect(createFn).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('when strict is set to admin', function () { | ||
describe('when strict is set to admin', function() { | ||
beforeEach(() => { | ||
const Auth0StoreStrategy = getAuth0StoreStrategy('test'); | ||
auth0StoreStrategy = new Auth0StoreStrategy( | ||
container, | ||
{} as ConfigModule, | ||
|
@@ -192,7 +195,7 @@ describe('Auth0 store strategy verify callback', function () { | |
clientSecret: 'fake', | ||
store: { callbackUrl: '/fakeCallbackUrl' }, | ||
} as Auth0Options, | ||
'admin' | ||
'admin', | ||
); | ||
}); | ||
|
||
|
@@ -209,7 +212,7 @@ describe('Auth0 store strategy verify callback', function () { | |
expect(data).toEqual( | ||
expect.objectContaining({ | ||
id: 'test3', | ||
}) | ||
}), | ||
); | ||
}); | ||
|
||
|
@@ -222,7 +225,7 @@ describe('Auth0 store strategy verify callback', function () { | |
expect(data).toEqual( | ||
expect.objectContaining({ | ||
id: 'test', | ||
}) | ||
}), | ||
); | ||
}); | ||
|
||
|
@@ -235,7 +238,7 @@ describe('Auth0 store strategy verify callback', function () { | |
expect(data).toEqual( | ||
expect.objectContaining({ | ||
id: 'test2', | ||
}) | ||
}), | ||
); | ||
expect(updateFn).toHaveBeenCalledTimes(1); | ||
}); | ||
|
@@ -249,7 +252,7 @@ describe('Auth0 store strategy verify callback', function () { | |
expect(data).toEqual( | ||
expect.objectContaining({ | ||
id: 'test4', | ||
}) | ||
}), | ||
); | ||
}); | ||
|
||
|
@@ -266,7 +269,7 @@ describe('Auth0 store strategy verify callback', function () { | |
expect(data).toEqual( | ||
expect.objectContaining({ | ||
id: 'test', | ||
}) | ||
}), | ||
); | ||
expect(createFn).toHaveBeenCalledTimes(1); | ||
}); | ||
|
Oops, something went wrong.