-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcustomer.ts
117 lines (81 loc) · 4.1 KB
/
customer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import Groups from '@data/demo/groups';
import Titles from '@data/demo/titles';
import type GroupData from '@data/faker/group';
import type TitleData from '@data/faker/title';
import type {CustomerCreator} from '@data/types/customer';
import {faker} from '@faker-js/faker';
const genders: string[] = Object.values(Titles).map((title: TitleData) => title.name);
const groups: string[] = Object.values(Groups).map((group: GroupData) => group.name);
const risksRating: string[] = ['None', 'Low', 'Medium', 'High'];
/**
* Create new customer to use on creation form on customer page on BO and FO
* @class
*/
export default class CustomerData {
public readonly id: number;
public readonly socialTitle: string;
public readonly firstName: string;
public readonly lastName: string;
public email: string;
public password: string;
public readonly birthDate: Date;
public readonly yearOfBirth: string;
public readonly monthOfBirth: string;
public readonly dayOfBirth: string;
public readonly enabled: boolean;
public readonly partnerOffers: boolean;
public readonly newsletter: boolean;
public readonly defaultCustomerGroup: string;
public readonly company: string;
public readonly allowedOutstandingAmount: number;
public readonly riskRating: string;
/**
* Constructor for class CustomerData
* @param customerToCreate {CustomerCreator} Could be used to force the value of some members
*/
constructor(customerToCreate: CustomerCreator = {}) {
/** @type {number} ID of the customer */
this.id = customerToCreate.id || 0;
/** @type {string} Social title of the customer (Mr, Mrs) */
this.socialTitle = customerToCreate.socialTitle || faker.helpers.arrayElement(genders);
/** @type {string} Firstname of the customer */
this.firstName = customerToCreate.firstName || faker.person.firstName();
/** @type {string} Lastname of the customer */
this.lastName = customerToCreate.lastName || faker.person.lastName();
/** @type {string} Email for the customer account */
this.email = customerToCreate.email || faker.internet.email(
{
firstName: this.firstName,
lastName: this.lastName,
provider: 'prestashop.com',
},
);
/** @type {string} Password for the customer account */
this.password = customerToCreate.password === undefined ? faker.internet.password() : customerToCreate.password;
/** @type {Date} Birthdate of the customer */
this.birthDate = customerToCreate.birthDate || faker.date.between({from: '1950-01-01', to: '2000-12-31'});
/** @type {string} Year of the birth 'yyyy' */
this.yearOfBirth = customerToCreate.yearOfBirth || this.birthDate.getFullYear().toString();
/** @type {string} Month of the birth 'mm' */
this.monthOfBirth = customerToCreate.monthOfBirth || (`0${this.birthDate.getMonth() + 1}`).slice(-2);
/** @type {string} Day of the birth 'dd' */
this.dayOfBirth = customerToCreate.dayOfBirth || (`0${this.birthDate.getDate()}`).slice(-2).toString();
/** @type {boolean} Status of the customer */
this.enabled = customerToCreate.enabled === undefined ? true : customerToCreate.enabled;
/** @type {boolean} True to enable partner offers */
this.partnerOffers = customerToCreate.partnerOffers === undefined ? true : customerToCreate.partnerOffers;
/** @type {string} Default group for the customer */
this.defaultCustomerGroup = customerToCreate.defaultCustomerGroup || faker.helpers.arrayElement(groups);
/** @type {boolean} True to enable sending newsletter to the customer */
this.newsletter = customerToCreate.newsletter === undefined ? false : customerToCreate.newsletter;
/** @type {string} Company for the customer */
this.company = customerToCreate.company || faker.company.name();
/** @type {Number} Allowed outstanding amount for the customer */
this.allowedOutstandingAmount = customerToCreate.allowedOutstandingAmount || faker.number.int({
min: 0,
max: 100,
});
/** @type {string} Risk rating for the customer */
this.riskRating = customerToCreate.riskRating || faker.helpers.arrayElement(risksRating);
}
}