-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add privacy context and canSelfDeleteAccount api
- Loading branch information
Showing
5 changed files
with
103 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { usecases } from '../../domain/usecases/index.js'; | ||
|
||
/** | ||
* Determines if a user can self-delete their account. | ||
* | ||
* @param {Object} params - The parameters for the function. | ||
* @param {number} params.userId - The ID of the user. | ||
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating if the user can self-delete their account. | ||
*/ | ||
export const canSelfDeleteAccount = async ({ userId }) => { | ||
return usecases.canSelfDeleteAccount({ userId }); | ||
}; |
19 changes: 19 additions & 0 deletions
19
api/src/privacy/domain/usecases/can-self-delete-account.usecase.js
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,19 @@ | ||
import { config } from '../../../shared/config.js'; | ||
|
||
/** | ||
* Determines if a user can self-delete their account. | ||
* | ||
* @param {Object} params - The parameters for the use case. | ||
* @param {number} params.userId - The ID of the user. | ||
* @param {Object} [params.featureToggles] - The feature toggles configuration. | ||
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating if self-account deletion is enabled. | ||
*/ | ||
const canSelfDeleteAccount = async ({ featureToggles = config.featureToggles }) => { | ||
const { isSelfAccountDeletionEnabled } = featureToggles; | ||
|
||
if (!isSelfAccountDeletionEnabled) return false; | ||
|
||
return true; | ||
}; | ||
|
||
export { canSelfDeleteAccount }; |
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,17 @@ | ||
import { dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
import { injectDependencies } from '../../../shared/infrastructure/utils/dependency-injection.js'; | ||
import { importNamedExportsFromDirectory } from '../../../shared/infrastructure/utils/import-named-exports-from-directory.js'; | ||
|
||
const path = dirname(fileURLToPath(import.meta.url)); | ||
|
||
const usecasesWithoutInjectedDependencies = { | ||
...(await importNamedExportsFromDirectory({ path: join(path, './'), ignoredFileNames: ['index.js'] })), | ||
}; | ||
|
||
const dependencies = {}; | ||
|
||
const usecases = injectDependencies(usecasesWithoutInjectedDependencies, dependencies); | ||
|
||
export { usecases }; |
34 changes: 34 additions & 0 deletions
34
api/tests/privacy/integration/domain/usecases/can-self-delete-account.usecase.test.js
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,34 @@ | ||
import { usecases } from '../../../../../src/privacy/domain/usecases/index.js'; | ||
import { databaseBuilder, expect } from '../../../../test-helper.js'; | ||
|
||
describe('Integration | Privacy | Domain | UseCase | can-self-delete-account', function () { | ||
context('Feature flag is disabled', function () { | ||
it('returns false', async function () { | ||
// given | ||
const featureToggles = { isSelfAccountDeletionEnabled: false }; | ||
const user = databaseBuilder.factory.buildUser(); | ||
await databaseBuilder.commit(); | ||
|
||
// when | ||
const result = await usecases.canSelfDeleteAccount({ userId: user.id, featureToggles }); | ||
|
||
// then | ||
expect(result).to.be.false; | ||
}); | ||
}); | ||
|
||
context('Feature flag is enabled', function () { | ||
it('returns true', async function () { | ||
// given | ||
const featureToggles = { isSelfAccountDeletionEnabled: true }; | ||
const user = databaseBuilder.factory.buildUser(); | ||
await databaseBuilder.commit(); | ||
|
||
// when | ||
const result = await usecases.canSelfDeleteAccount({ userId: user.id, featureToggles }); | ||
|
||
// then | ||
expect(result).to.be.true; | ||
}); | ||
}); | ||
}); |
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,21 @@ | ||
import { canSelfDeleteAccount } from '../../../../../src/privacy/application/api/users-api.js'; | ||
import { usecases } from '../../../../../src/privacy/domain/usecases/index.js'; | ||
import { expect, sinon } from '../../../../test-helper.js'; | ||
|
||
describe('Unit | Privacy | Application | Api | users', function () { | ||
describe('#canSelfDeleteAccount', function () { | ||
it('indicates if a user can self delete an account', async function () { | ||
// given | ||
const userId = Symbol('123'); | ||
|
||
sinon.stub(usecases, 'canSelfDeleteAccount'); | ||
usecases.canSelfDeleteAccount.withArgs({ userId }).resolves(true); | ||
|
||
// when | ||
const result = await canSelfDeleteAccount({ userId }); | ||
|
||
// then | ||
expect(result).to.equal(true); | ||
}); | ||
}); | ||
}); |