mirror of
https://github.com/standardnotes/server
synced 2026-10-12 06:13:10 -04:00
feat(domain-core): add email subscription rejection levels
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { EmailSubscriptionRejectionLevel } from './EmailSubscriptionRejectionLevel'
|
||||
|
||||
describe('EmailSubscriptionRejectionLevel', () => {
|
||||
it('should create a value object', () => {
|
||||
const valueOrError = EmailSubscriptionRejectionLevel.create(EmailSubscriptionRejectionLevel.LEVELS.SignIn)
|
||||
|
||||
expect(valueOrError.isFailed()).toBeFalsy()
|
||||
expect(valueOrError.getValue().value).toEqual('SIGN_IN')
|
||||
})
|
||||
|
||||
it('should not create an invalid value object', () => {
|
||||
for (const value of ['', undefined, null, 0, 'FOOBAR']) {
|
||||
const valueOrError = EmailSubscriptionRejectionLevel.create(value as string)
|
||||
|
||||
expect(valueOrError.isFailed()).toBeTruthy()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Result } from '../Core/Result'
|
||||
import { ValueObject } from '../Core/ValueObject'
|
||||
|
||||
import { EmailSubscriptionRejectionLevelProps } from './EmailSubscriptionRejectionLevelProps'
|
||||
|
||||
export class EmailSubscriptionRejectionLevel extends ValueObject<EmailSubscriptionRejectionLevelProps> {
|
||||
static readonly LEVELS = {
|
||||
SignIn: 'SIGN_IN',
|
||||
Marketing: 'MARKETING',
|
||||
FailedCloudBackup: 'FAILED_CLOUD_BACKUP',
|
||||
FailedEmailBackup: 'FAILED_EMAIL_BACKUP',
|
||||
}
|
||||
|
||||
get value(): string {
|
||||
return this.props.value
|
||||
}
|
||||
|
||||
private constructor(props: EmailSubscriptionRejectionLevelProps) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
static create(name: string): Result<EmailSubscriptionRejectionLevel> {
|
||||
const isValidName = Object.values(this.LEVELS).includes(name)
|
||||
if (!isValidName) {
|
||||
return Result.fail<EmailSubscriptionRejectionLevel>(`Invalid subscription rejection level: ${name}`)
|
||||
} else {
|
||||
return Result.ok<EmailSubscriptionRejectionLevel>(new EmailSubscriptionRejectionLevel({ value: name }))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface EmailSubscriptionRejectionLevelProps {
|
||||
value: string
|
||||
}
|
||||
@@ -20,6 +20,9 @@ export * from './Core/Validator'
|
||||
export * from './Core/ValueObject'
|
||||
export * from './Core/ValueObjectProps'
|
||||
|
||||
export * from './Email/EmailSubscriptionRejectionLevel'
|
||||
export * from './Email/EmailSubscriptionRejectionLevelProps'
|
||||
|
||||
export * from './Mapping/MapperInterface'
|
||||
|
||||
export * from './Subscription/SubscriptionPlanName'
|
||||
|
||||
Reference in New Issue
Block a user