@things-factory/organization 10.1.278 → 10.1.279
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +24 -8
- package/CHANGELOG.md +0 -8
- package/dist-client/bootstrap.js.map +0 -1
- package/dist-client/component/approval-line-brief.js.map +0 -1
- package/dist-client/component/approval-line-edit.js.map +0 -1
- package/dist-client/component/approval-line-items-editor-popup.js.map +0 -1
- package/dist-client/component/approval-line-items-editor.js.map +0 -1
- package/dist-client/component/approval-line-selector.js.map +0 -1
- package/dist-client/component/approval-line-templates-manager.js.map +0 -1
- package/dist-client/component/approval-line-view.js.map +0 -1
- package/dist-client/component/assignees-editor-popup.js.map +0 -1
- package/dist-client/component/assignees-editor.js.map +0 -1
- package/dist-client/component/assignees-view.js.map +0 -1
- package/dist-client/component/copy-from.js.map +0 -1
- package/dist-client/component/department-selector.js.map +0 -1
- package/dist-client/component/department-view.js.map +0 -1
- package/dist-client/component/index.js.map +0 -1
- package/dist-client/component/popup-actions-row.test.d.ts +0 -1
- package/dist-client/component/popup-actions-row.test.js +0 -42
- package/dist-client/component/popup-actions-row.test.js.map +0 -1
- package/dist-client/component/recipients-editor-popup.js.map +0 -1
- package/dist-client/component/recipients-editor.js.map +0 -1
- package/dist-client/component/recipients-view.js.map +0 -1
- package/dist-client/entity360/department-360.js.map +0 -1
- package/dist-client/entity360/person-membership-section.js.map +0 -1
- package/dist-client/filters-form/filter-department-object.js.map +0 -1
- package/dist-client/filters-form/ox-filter-department-object.js.map +0 -1
- package/dist-client/grist-editor/grist-editor-approval-line.js.map +0 -1
- package/dist-client/grist-editor/grist-editor-assignees.js.map +0 -1
- package/dist-client/grist-editor/grist-editor-department-object.js.map +0 -1
- package/dist-client/grist-editor/grist-editor-recipients.js.map +0 -1
- package/dist-client/grist-editor/grist-renderer-approval-line.js.map +0 -1
- package/dist-client/grist-editor/grist-renderer-assignees.js.map +0 -1
- package/dist-client/grist-editor/grist-renderer-department-object.js.map +0 -1
- package/dist-client/grist-editor/grist-renderer-recipients.js.map +0 -1
- package/dist-client/index.js.map +0 -1
- package/dist-client/my-picture-model.js.map +0 -1
- package/dist-client/my-picture.js.map +0 -1
- package/dist-client/pages/approval-line/approval-line-list-page.js.map +0 -1
- package/dist-client/pages/approval-line/common-approval-line-templates-page.js.map +0 -1
- package/dist-client/pages/approval-line/my-approval-line-templates-page.js.map +0 -1
- package/dist-client/pages/department/department-importer.js.map +0 -1
- package/dist-client/pages/department/department-list-page.js.map +0 -1
- package/dist-client/pages/department/department-patch.js.map +0 -1
- package/dist-client/pages/employee/employee-importer.js.map +0 -1
- package/dist-client/pages/employee/employee-list-page.js.map +0 -1
- package/dist-client/pages/employee-profile/employee-profile-files.js.map +0 -1
- package/dist-client/pages/employee-profile/employee-profile-form.js.map +0 -1
- package/dist-client/pages/employee-profile/employee-profile-list-page.js.map +0 -1
- package/dist-client/pages/employee-profile/employee-profile-preview.js.map +0 -1
- package/dist-client/pages/employee-profile/my-employee-profile-page.js.map +0 -1
- package/dist-client/route.js.map +0 -1
- package/dist-client/tsconfig.tsbuildinfo +0 -1
- package/dist-client/types/approval-line.js.map +0 -1
- package/dist-client/types/contact.js.map +0 -1
- package/dist-client/types/department.js.map +0 -1
- package/dist-client/types/employee.js.map +0 -1
- package/dist-client/types/index.js.map +0 -1
- package/dist-client/types/org-member.js.map +0 -1
- package/dist-server/ai-entry/employee-profile-entry.js.map +0 -1
- package/dist-server/ai-entry/entry-target-shape.js.map +0 -1
- package/dist-server/ai-entry/organization-entry-rules.js.map +0 -1
- package/dist-server/ai-entry/organization-entry-targets.js.map +0 -1
- package/dist-server/controllers/register-employee-as-system-user.js.map +0 -1
- package/dist-server/index.js.map +0 -1
- package/dist-server/migrations/1723861013111-seed-organization-codes.js.map +0 -1
- package/dist-server/migrations/index.js.map +0 -1
- package/dist-server/role-tasks.js.map +0 -1
- package/dist-server/routes.js.map +0 -1
- package/dist-server/service/approval-line/approval-line-item.js.map +0 -1
- package/dist-server/service/approval-line/approval-line-mutation.js.map +0 -1
- package/dist-server/service/approval-line/approval-line-query.js.map +0 -1
- package/dist-server/service/approval-line/approval-line-type.js.map +0 -1
- package/dist-server/service/approval-line/approval-line.js.map +0 -1
- package/dist-server/service/approval-line/index.js.map +0 -1
- package/dist-server/service/audience/audience-member.js.map +0 -1
- package/dist-server/service/audience/audience.js.map +0 -1
- package/dist-server/service/certificate/employment-certificate-rules.js.map +0 -1
- package/dist-server/service/certificate/employment-certificate-templates.js.map +0 -1
- package/dist-server/service/certificate/employment-certificates.js.map +0 -1
- package/dist-server/service/department/department-history.js.map +0 -1
- package/dist-server/service/department/department-mutation.js.map +0 -1
- package/dist-server/service/department/department-parent.js.map +0 -1
- package/dist-server/service/department/department-query.js.map +0 -1
- package/dist-server/service/department/department-type.js.map +0 -1
- package/dist-server/service/department/department.js.map +0 -1
- package/dist-server/service/department/event-subscriber.js.map +0 -1
- package/dist-server/service/department/index.js.map +0 -1
- package/dist-server/service/domain-reference.js.map +0 -1
- package/dist-server/service/employee/employee-control-no.js.map +0 -1
- package/dist-server/service/employee/employee-day.js.map +0 -1
- package/dist-server/service/employee/employee-history.js.map +0 -1
- package/dist-server/service/employee/employee-mutation.js.map +0 -1
- package/dist-server/service/employee/employee-private.js.map +0 -1
- package/dist-server/service/employee/employee-query.js.map +0 -1
- package/dist-server/service/employee/employee-type.js.map +0 -1
- package/dist-server/service/employee/employee.js.map +0 -1
- package/dist-server/service/employee/event-subscriber.js.map +0 -1
- package/dist-server/service/employee/index.js.map +0 -1
- package/dist-server/service/employee/my-employee-refusal.js.map +0 -1
- package/dist-server/service/employee/my-employee.js.map +0 -1
- package/dist-server/service/employee/working-employees.js.map +0 -1
- package/dist-server/service/employee-profile/employee-profile-document.js.map +0 -1
- package/dist-server/service/employee-profile/employee-profile-mutation.js.map +0 -1
- package/dist-server/service/employee-profile/employee-profile-query.js.map +0 -1
- package/dist-server/service/employee-profile/employee-profile-rows.js.map +0 -1
- package/dist-server/service/employee-profile/employee-profile-rules.js.map +0 -1
- package/dist-server/service/employee-profile/employee-profile-type.js.map +0 -1
- package/dist-server/service/employee-profile/employee-profile.js.map +0 -1
- package/dist-server/service/employee-profile/index.js.map +0 -1
- package/dist-server/service/index.js.map +0 -1
- package/dist-server/tsconfig.tsbuildinfo +0 -1
- package/dist-server/work-doors.js.map +0 -1
- package/spec/unit/approval-line.spec.ts +0 -329
- package/spec/unit/department.spec.ts +0 -253
- package/spec/unit/employee.spec.ts +0 -271
- package/spec/unit/my-employee.spec.ts +0 -102
- package/tests/approval-line-brief-plan.test.ts +0 -35
- package/tests/approval-line-edit.test.ts +0 -78
- package/tests/approval-line-mark.test.ts +0 -68
- package/tests/approval-line-step-fields.test.ts +0 -108
- package/tests/assignees-editor-no-role.test.ts +0 -32
- package/tests/audience.test.ts +0 -85
- package/tests/copy-from.test.ts +0 -17
- package/tests/department-open-fields.test.ts +0 -72
- package/tests/department-parent.test.ts +0 -187
- package/tests/department-patch.test.ts +0 -52
- package/tests/department-query-shape.test.ts +0 -130
- package/tests/department-selector.test.ts +0 -32
- package/tests/domain-reference.test.ts +0 -186
- package/tests/employee-day.test.ts +0 -165
- package/tests/employee-private.test.ts +0 -37
- package/tests/employee-profile-db.test.ts +0 -261
- package/tests/employee-profile-document.test.ts +0 -282
- package/tests/employee-profile-entry.test.ts +0 -72
- package/tests/employee-profile-rules.test.ts +0 -103
- package/tests/entity360.test.ts +0 -36
- package/tests/my-picture.test.ts +0 -21
- package/tests/organization-entry-targets.test.ts +0 -236
- package/tests/refusals-in-korean.test.ts +0 -48
- package/tests/register-employee-role.test.ts +0 -97
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A department's manager and an employee's supervisor, department and user are looked up inside the caller's domain.
|
|
3
|
-
*
|
|
4
|
-
* The lookups asked by id alone, so a mutation run in one domain could link a row of another: an employee of
|
|
5
|
-
* domain B as the manager of a department of domain A, a user who is not a member of A as an employee of A.
|
|
6
|
-
* This runs the real mutations on sqlite and reads the links back from the table.
|
|
7
|
-
*/
|
|
8
|
-
import 'reflect-metadata'
|
|
9
|
-
|
|
10
|
-
const { existsSync } = require('fs')
|
|
11
|
-
const { join } = require('path')
|
|
12
|
-
const { DataSource } = require('typeorm')
|
|
13
|
-
|
|
14
|
-
const shell = require('@things-factory/shell')
|
|
15
|
-
const authBase = require('@things-factory/auth-base')
|
|
16
|
-
const contact = require('@things-factory/contact')
|
|
17
|
-
/* contact's Contact names a biz-base Counterparty (ADR-0122 decision C), so its entities come along. */
|
|
18
|
-
const bizBase = require('@things-factory/biz-base')
|
|
19
|
-
|
|
20
|
-
function loadCompiled(modulePath: string): any {
|
|
21
|
-
const resolved = join(__dirname, '..', 'dist-server', `${modulePath}.js`)
|
|
22
|
-
if (!existsSync(resolved)) {
|
|
23
|
-
throw new Error(`organization build output is missing: ${resolved}\nBuild it first: npm run build:server`)
|
|
24
|
-
}
|
|
25
|
-
return require(resolved)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let dataSource: any
|
|
29
|
-
let Department: any
|
|
30
|
-
let Employee: any
|
|
31
|
-
let DepartmentMutation: any
|
|
32
|
-
let EmployeeMutation: any
|
|
33
|
-
|
|
34
|
-
let domain: any
|
|
35
|
-
let other: any
|
|
36
|
-
let user: any
|
|
37
|
-
let member: any
|
|
38
|
-
let outsider: any
|
|
39
|
-
let ours: any
|
|
40
|
-
let theirs: any
|
|
41
|
-
let ourTeam: any
|
|
42
|
-
let theirTeam: any
|
|
43
|
-
|
|
44
|
-
beforeAll(async () => {
|
|
45
|
-
const organization = loadCompiled('service/index')
|
|
46
|
-
Department = loadCompiled('service/department/department').Department
|
|
47
|
-
Employee = loadCompiled('service/employee/employee').Employee
|
|
48
|
-
DepartmentMutation = loadCompiled('service/department/department-mutation').DepartmentMutation
|
|
49
|
-
EmployeeMutation = loadCompiled('service/employee/employee-mutation').EmployeeMutation
|
|
50
|
-
|
|
51
|
-
dataSource = new DataSource({
|
|
52
|
-
type: 'sqlite',
|
|
53
|
-
database: ':memory:',
|
|
54
|
-
synchronize: true,
|
|
55
|
-
dropSchema: true,
|
|
56
|
-
namingStrategy: new shell.NamingStrategy(),
|
|
57
|
-
entities: [...shell.entities, ...authBase.entities, ...bizBase.entities, ...contact.entities, ...organization.entities],
|
|
58
|
-
logging: false
|
|
59
|
-
})
|
|
60
|
-
await dataSource.initialize()
|
|
61
|
-
shell.addDataSource('default', dataSource)
|
|
62
|
-
shell.addDataSource('tx', dataSource)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
beforeEach(async () => {
|
|
66
|
-
await dataSource.synchronize(true)
|
|
67
|
-
const domains = dataSource.getRepository(shell.Domain)
|
|
68
|
-
domain = await domains.save({ name: 'ours', subdomain: 'ours' })
|
|
69
|
-
other = await domains.save({ name: 'theirs', subdomain: 'theirs' })
|
|
70
|
-
|
|
71
|
-
const users = dataSource.getRepository(authBase.User)
|
|
72
|
-
user = await users.save({ name: 'tester', email: 'tester@domain-reference.test', domains: [domain] })
|
|
73
|
-
member = await users.save({ name: 'member', email: 'member@domain-reference.test', domains: [domain] })
|
|
74
|
-
outsider = await users.save({ name: 'outsider', email: 'outsider@domain-reference.test', domains: [other] })
|
|
75
|
-
|
|
76
|
-
const employees = dataSource.getRepository(Employee)
|
|
77
|
-
ours = await employees.save({ domain, controlNo: 'E1', name: 'ours' })
|
|
78
|
-
theirs = await employees.save({ domain: other, controlNo: 'E1', name: 'theirs' })
|
|
79
|
-
|
|
80
|
-
const departments = dataSource.getRepository(Department)
|
|
81
|
-
ourTeam = await departments.save({ domain, controlNo: 'T1', name: 'our team' })
|
|
82
|
-
theirTeam = await departments.save({ domain: other, controlNo: 'T1', name: 'their team' })
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
afterAll(async () => {
|
|
86
|
-
if (!dataSource) return
|
|
87
|
-
shell.removeDataSource('default')
|
|
88
|
-
shell.removeDataSource('tx')
|
|
89
|
-
await dataSource.destroy()
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
const context = () => ({ state: { domain, user, tx: dataSource.manager } })
|
|
93
|
-
|
|
94
|
-
async function managerOf(id: string) {
|
|
95
|
-
return (await dataSource.getRepository(Department).findOne({ where: { id }, relations: ['manager'] }))?.manager?.id ?? null
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async function linksOf(id: string) {
|
|
99
|
-
const row = await dataSource.getRepository(Employee).findOne({ where: { id }, relations: ['supervisor', 'department', 'user'] })
|
|
100
|
-
return { supervisor: row?.supervisor?.id ?? null, department: row?.department?.id ?? null, user: row?.user?.id ?? null }
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
describe("a department's manager comes from the caller's domain", () => {
|
|
104
|
-
it('an employee of this domain is accepted', async () => {
|
|
105
|
-
const created = await new DepartmentMutation().createDepartment({ controlNo: 'T2', name: 'new', manager: { id: ours.id } }, context())
|
|
106
|
-
expect(await managerOf(created.id)).toBe(ours.id)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('createDepartment refuses an employee of another domain', async () => {
|
|
110
|
-
await expect(
|
|
111
|
-
new DepartmentMutation().createDepartment({ controlNo: 'T2', name: 'new', manager: { id: theirs.id } }, context())
|
|
112
|
-
).rejects.toThrow(/manager not found in this domain/)
|
|
113
|
-
expect(await dataSource.getRepository(Department).countBy({ name: 'new' })).toBe(0)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('updateDepartment refuses an employee of another domain', async () => {
|
|
117
|
-
await expect(
|
|
118
|
-
new DepartmentMutation().updateDepartment(ourTeam.id, { manager: { id: theirs.id } }, context())
|
|
119
|
-
).rejects.toThrow(/manager not found in this domain/)
|
|
120
|
-
expect(await managerOf(ourTeam.id)).toBeNull()
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('updateMultipleDepartment refuses it on a new row and on an edited one', async () => {
|
|
124
|
-
const mutation = new DepartmentMutation()
|
|
125
|
-
await expect(
|
|
126
|
-
mutation.updateMultipleDepartment([{ cuFlag: '+', controlNo: 'T2', name: 'new', manager: { id: theirs.id } }], context())
|
|
127
|
-
).rejects.toThrow(/manager not found in this domain/)
|
|
128
|
-
await expect(
|
|
129
|
-
mutation.updateMultipleDepartment([{ cuFlag: 'M', id: ourTeam.id, manager: { id: theirs.id } }], context())
|
|
130
|
-
).rejects.toThrow(/manager not found in this domain/)
|
|
131
|
-
expect(await managerOf(ourTeam.id)).toBeNull()
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('null still clears the manager', async () => {
|
|
135
|
-
await new DepartmentMutation().updateDepartment(ourTeam.id, { manager: { id: ours.id } }, context())
|
|
136
|
-
await new DepartmentMutation().updateDepartment(ourTeam.id, { manager: null }, context())
|
|
137
|
-
expect(await managerOf(ourTeam.id)).toBeNull()
|
|
138
|
-
})
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
describe("an employee's supervisor, department and user come from the caller's domain", () => {
|
|
142
|
-
it('rows of this domain, and a member of it, are accepted', async () => {
|
|
143
|
-
const created = await new EmployeeMutation().createEmployee(
|
|
144
|
-
{ controlNo: 'E2', name: 'new', supervisor: { id: ours.id }, department: { id: ourTeam.id }, user: { id: member.id } },
|
|
145
|
-
context()
|
|
146
|
-
)
|
|
147
|
-
expect(await linksOf(created.id)).toEqual({ supervisor: ours.id, department: ourTeam.id, user: member.id })
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
it.each([
|
|
151
|
-
['supervisor', () => ({ supervisor: { id: theirs.id } })],
|
|
152
|
-
['department', () => ({ department: { id: theirTeam.id } })],
|
|
153
|
-
['user', () => ({ user: { id: outsider.id } })]
|
|
154
|
-
])('createEmployee refuses a %s of another domain', async (what, patch) => {
|
|
155
|
-
await expect(
|
|
156
|
-
new EmployeeMutation().createEmployee({ controlNo: 'E2', name: 'new', ...patch() }, context())
|
|
157
|
-
).rejects.toThrow(new RegExp(`${what} not found in this domain`))
|
|
158
|
-
expect(await dataSource.getRepository(Employee).countBy({ controlNo: 'E2' })).toBe(0)
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
it.each([
|
|
162
|
-
['supervisor', () => ({ supervisor: { id: theirs.id } })],
|
|
163
|
-
['department', () => ({ department: { id: theirTeam.id } })],
|
|
164
|
-
['user', () => ({ user: { id: outsider.id } })]
|
|
165
|
-
])('updateEmployee refuses a %s of another domain', async (what, patch) => {
|
|
166
|
-
await expect(new EmployeeMutation().updateEmployee(ours.id, patch(), context())).rejects.toThrow(
|
|
167
|
-
new RegExp(`${what} not found in this domain`)
|
|
168
|
-
)
|
|
169
|
-
expect(await linksOf(ours.id)).toEqual({ supervisor: null, department: null, user: null })
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it.each([
|
|
173
|
-
['supervisor', () => ({ supervisor: { id: theirs.id } })],
|
|
174
|
-
['department', () => ({ department: { id: theirTeam.id } })],
|
|
175
|
-
['user', () => ({ user: { id: outsider.id } })]
|
|
176
|
-
])('updateMultipleEmployee refuses a %s of another domain on a new row and on an edited one', async (what, patch) => {
|
|
177
|
-
const mutation = new EmployeeMutation()
|
|
178
|
-
await expect(
|
|
179
|
-
mutation.updateMultipleEmployee([{ cuFlag: '+', controlNo: 'E2', name: 'new', ...patch() }], context())
|
|
180
|
-
).rejects.toThrow(new RegExp(`${what} not found in this domain`))
|
|
181
|
-
await expect(
|
|
182
|
-
mutation.updateMultipleEmployee([{ cuFlag: 'M', id: ours.id, ...patch() }], context())
|
|
183
|
-
).rejects.toThrow(new RegExp(`${what} not found in this domain`))
|
|
184
|
-
expect(await linksOf(ours.id)).toEqual({ supervisor: null, department: null, user: null })
|
|
185
|
-
})
|
|
186
|
-
})
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hiredOn and retiredOn are calendar days, and the grid's date editor sends them as 'YYYY-MM-DD'.
|
|
3
|
-
*
|
|
4
|
-
* They were declared `Date`, so GraphQL typed them as a date-time and refused the grid's own value before
|
|
5
|
-
* any resolver ran: 'Variable "$patches" got invalid value "2025-12-31" at "patches[0].retiredOn"'. The
|
|
6
|
-
* employee list could not save a retire day at all.
|
|
7
|
-
*
|
|
8
|
-
* This sends the grid's patch through the server's own EmployeePatch and Employee types and the real
|
|
9
|
-
* updateMultipleEmployee, on sqlite, and reads the day back — from the table, from the history row and
|
|
10
|
-
* through GraphQL — unchanged.
|
|
11
|
-
*/
|
|
12
|
-
import 'reflect-metadata'
|
|
13
|
-
|
|
14
|
-
const { existsSync } = require('fs')
|
|
15
|
-
const { join } = require('path')
|
|
16
|
-
const { DataSource } = require('typeorm')
|
|
17
|
-
const { buildSchema, Resolver, Query, Mutation, Arg, Ctx } = require('type-graphql')
|
|
18
|
-
const { graphql } = require('graphql')
|
|
19
|
-
|
|
20
|
-
const shell = require('@things-factory/shell')
|
|
21
|
-
const authBase = require('@things-factory/auth-base')
|
|
22
|
-
const contact = require('@things-factory/contact')
|
|
23
|
-
/* contact's Contact names a biz-base Counterparty (ADR-0122 decision C), so its entities come along. */
|
|
24
|
-
const bizBase = require('@things-factory/biz-base')
|
|
25
|
-
|
|
26
|
-
function loadCompiled(modulePath: string): any {
|
|
27
|
-
const resolved = join(__dirname, '..', 'dist-server', `${modulePath}.js`)
|
|
28
|
-
if (!existsSync(resolved)) {
|
|
29
|
-
throw new Error(`organization build output is missing: ${resolved}\nBuild it first: npm run build:server`)
|
|
30
|
-
}
|
|
31
|
-
return require(resolved)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let dataSource: any
|
|
35
|
-
let organization: any
|
|
36
|
-
let Employee: any
|
|
37
|
-
let EmployeeHistory: any
|
|
38
|
-
let schema: any
|
|
39
|
-
let domain: any
|
|
40
|
-
let user: any
|
|
41
|
-
|
|
42
|
-
const SAVE = `
|
|
43
|
-
mutation ($patches: [EmployeePatch!]!) {
|
|
44
|
-
updateMultipleEmployee(patches: $patches) { id hiredOn retiredOn }
|
|
45
|
-
}
|
|
46
|
-
`
|
|
47
|
-
|
|
48
|
-
beforeAll(async () => {
|
|
49
|
-
organization = loadCompiled('service/index')
|
|
50
|
-
Employee = loadCompiled('service/employee/employee').Employee
|
|
51
|
-
EmployeeHistory = loadCompiled('service/employee/employee-history').EmployeeHistory
|
|
52
|
-
const { EmployeeHistoryEntitySubscriber } = loadCompiled('service/employee/event-subscriber')
|
|
53
|
-
const { EmployeeMutation } = loadCompiled('service/employee/employee-mutation')
|
|
54
|
-
const { EmployeePatch } = loadCompiled('service/employee/employee-type')
|
|
55
|
-
|
|
56
|
-
dataSource = new DataSource({
|
|
57
|
-
type: 'sqlite',
|
|
58
|
-
database: ':memory:',
|
|
59
|
-
synchronize: true,
|
|
60
|
-
dropSchema: true,
|
|
61
|
-
namingStrategy: new shell.NamingStrategy(),
|
|
62
|
-
entities: [...shell.entities, ...authBase.entities, ...bizBase.entities, ...contact.entities, ...organization.entities],
|
|
63
|
-
subscribers: [EmployeeHistoryEntitySubscriber],
|
|
64
|
-
logging: false
|
|
65
|
-
})
|
|
66
|
-
await dataSource.initialize()
|
|
67
|
-
shell.addDataSource('default', dataSource)
|
|
68
|
-
shell.addDataSource('tx', dataSource)
|
|
69
|
-
|
|
70
|
-
/* The real mutation, behind the real input and output types. Its @transaction and @privilege directives are
|
|
71
|
-
* the framework's; the context below stands in for what they set up. */
|
|
72
|
-
class EmployeeDayProbe {
|
|
73
|
-
/* A schema needs a Query field; this one is never asked. */
|
|
74
|
-
probe() {
|
|
75
|
-
return true
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async updateMultipleEmployee(patches: any[], context: any) {
|
|
79
|
-
return await new EmployeeMutation().updateMultipleEmployee(patches, context)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
Arg('patches', () => [EmployeePatch])(EmployeeDayProbe.prototype, 'updateMultipleEmployee', 0)
|
|
83
|
-
Ctx()(EmployeeDayProbe.prototype, 'updateMultipleEmployee', 1)
|
|
84
|
-
Mutation(() => [Employee])(
|
|
85
|
-
EmployeeDayProbe.prototype,
|
|
86
|
-
'updateMultipleEmployee',
|
|
87
|
-
Object.getOwnPropertyDescriptor(EmployeeDayProbe.prototype, 'updateMultipleEmployee')
|
|
88
|
-
)
|
|
89
|
-
Query(() => Boolean)(EmployeeDayProbe.prototype, 'probe', Object.getOwnPropertyDescriptor(EmployeeDayProbe.prototype, 'probe'))
|
|
90
|
-
Resolver()(EmployeeDayProbe)
|
|
91
|
-
|
|
92
|
-
schema = await buildSchema({ resolvers: [EmployeeDayProbe], validate: false })
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
beforeEach(async () => {
|
|
96
|
-
await dataSource.synchronize(true)
|
|
97
|
-
domain = await dataSource.getRepository(shell.Domain).save({ name: 'employee-day', subdomain: 'employee-day' })
|
|
98
|
-
user = await dataSource.getRepository(authBase.User).save({ name: 'tester', email: 'tester@employee-day.test' })
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
afterAll(async () => {
|
|
102
|
-
if (!dataSource) return
|
|
103
|
-
shell.removeDataSource('default')
|
|
104
|
-
shell.removeDataSource('tx')
|
|
105
|
-
await dataSource.destroy()
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
async function save(patches: any[]) {
|
|
109
|
-
return await graphql({
|
|
110
|
-
schema,
|
|
111
|
-
source: SAVE,
|
|
112
|
-
variableValues: { patches },
|
|
113
|
-
contextValue: { state: { domain, user, tx: dataSource.manager } }
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async function seedEmployee() {
|
|
118
|
-
return await dataSource.getRepository(Employee).save({ domain, controlNo: 'E-1', name: 'Kim', hiredOn: '2020-01-15' })
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
describe('employee hire and retire days are calendar days', () => {
|
|
122
|
-
it("the grid's patch with retiredOn '2025-12-31' saves and reads back unchanged", async () => {
|
|
123
|
-
const employee = await seedEmployee()
|
|
124
|
-
|
|
125
|
-
const result = await save([{ id: employee.id, cuFlag: 'M', retiredOn: '2025-12-31' }])
|
|
126
|
-
|
|
127
|
-
expect(result.errors).toBeUndefined()
|
|
128
|
-
expect(result.data.updateMultipleEmployee).toEqual([{ id: employee.id, hiredOn: '2020-01-15', retiredOn: '2025-12-31' }])
|
|
129
|
-
|
|
130
|
-
const stored = await dataSource.getRepository(Employee).findOneBy({ id: employee.id })
|
|
131
|
-
expect(stored.retiredOn).toBe('2025-12-31')
|
|
132
|
-
expect(stored.hiredOn).toBe('2020-01-15')
|
|
133
|
-
|
|
134
|
-
const history = await dataSource.getRepository(EmployeeHistory).find({ where: { originalId: employee.id } })
|
|
135
|
-
expect(history.map(row => row.retiredOn)).toContain('2025-12-31')
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
it('hiredOn edited in the grid saves too', async () => {
|
|
139
|
-
const employee = await seedEmployee()
|
|
140
|
-
|
|
141
|
-
const result = await save([{ id: employee.id, cuFlag: 'M', hiredOn: '2021-03-02' }])
|
|
142
|
-
|
|
143
|
-
expect(result.errors).toBeUndefined()
|
|
144
|
-
expect((await dataSource.getRepository(Employee).findOneBy({ id: employee.id })).hiredOn).toBe('2021-03-02')
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
it("a cleared date cell ('') removes the day", async () => {
|
|
148
|
-
const employee = await seedEmployee()
|
|
149
|
-
|
|
150
|
-
const result = await save([{ id: employee.id, cuFlag: 'M', hiredOn: '' }])
|
|
151
|
-
|
|
152
|
-
expect(result.errors).toBeUndefined()
|
|
153
|
-
expect((await dataSource.getRepository(Employee).findOneBy({ id: employee.id })).hiredOn).toBeNull()
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
it('a value that is not a calendar day is refused, not stored', async () => {
|
|
157
|
-
const employee = await seedEmployee()
|
|
158
|
-
|
|
159
|
-
for (const value of ['2025-12-31T00:00:00.000Z', '2025-02-30', '45657']) {
|
|
160
|
-
const result = await save([{ id: employee.id, cuFlag: 'M', retiredOn: value }])
|
|
161
|
-
expect(result.errors?.[0]?.message).toMatch(/retiredOn must be a calendar day/)
|
|
162
|
-
}
|
|
163
|
-
expect((await dataSource.getRepository(Employee).findOneBy({ id: employee.id })).retiredOn).toBeNull()
|
|
164
|
-
})
|
|
165
|
-
})
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs'
|
|
2
|
-
import { join } from 'path'
|
|
3
|
-
|
|
4
|
-
import { EMPLOYEE_PRIVATE_FIELDS, privateFieldsOf, refusePrivateWrite } from '../server/service/employee/employee-private'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* An employee's pay account is HR-payroll's (ADR-0139): read under `employee-private`, apart from the roster every
|
|
8
|
-
* seat reads, and written through its own door - a door is what declares the privilege (no directive, no privilege row).
|
|
9
|
-
*/
|
|
10
|
-
describe("an employee's pay account", () => {
|
|
11
|
-
it('★ is declared under employee-private on the employee and its history - the declaration, not a resolver', () => {
|
|
12
|
-
for (const file of ['employee.ts', 'employee-history.ts']) {
|
|
13
|
-
const source = readFileSync(join(__dirname, '..', 'server', 'service', 'employee', file), 'utf8')
|
|
14
|
-
for (const field of EMPLOYEE_PRIVATE_FIELDS) {
|
|
15
|
-
expect([file, field, new RegExp(`@privilege\\(category: "employee-private", privilege: "query", domainOwnerGranted: false\\)[^\\n]*\\n @Field\\(\\{ nullable: true \\}\\)\\n ${field}\\?:`).test(source)]).toEqual([file, field, true])
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('★ a patch that writes it is told apart from one that leaves it alone', () => {
|
|
21
|
-
expect(privateFieldsOf({ name: '홍길동', bankAccount: '123', bankName: undefined })).toEqual(['bankAccount'])
|
|
22
|
-
expect(privateFieldsOf({ name: '홍길동' })).toEqual([])
|
|
23
|
-
expect(privateFieldsOf({ bankName: '' })).toEqual(['bankName'])
|
|
24
|
-
expect(privateFieldsOf(null)).toEqual([])
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('★ the roster writes refuse it; its own door asks employee-private:mutation', () => {
|
|
28
|
-
expect(() => refusePrivateWrite([{ name: '홍길동' }, { bankAccount: '123' }])).toThrow(/updateEmployeePayAccount/)
|
|
29
|
-
expect(() => refusePrivateWrite([{ name: '홍길동' }])).not.toThrow()
|
|
30
|
-
const source = readFileSync(join(__dirname, '..', 'server', 'service', 'employee', 'employee-mutation.ts'), 'utf8')
|
|
31
|
-
expect(source).toMatch(/@privilege\(category: "employee-private", privilege: "mutation", domainOwnerGranted: false\)[^\n]*\n(?: @[^\n]*\n)* async updateEmployeePayAccount\(/)
|
|
32
|
-
for (const door of ['createEmployee', 'updateEmployee', 'updateMultipleEmployee', 'importEmployees']) {
|
|
33
|
-
const body = source.slice(source.indexOf(`async ${door}(`), source.indexOf(`async ${door}(`) + 600)
|
|
34
|
-
expect([door, /refusePrivateWrite\(/.test(body)]).toEqual([door, true])
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
})
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The profile's doors, through GraphQL on sqlite (ADR-0169 decisions 3 · 4): the employee writes their own and nobody
|
|
3
|
-
* else's, an account not linked to an employee has none, and the list gives every active employee with theirs.
|
|
4
|
-
*
|
|
5
|
-
* The real resolvers and types are built into a schema; @privilege and @transaction are the framework's, and the context
|
|
6
|
-
* below stands in for what they set up. What each door asks is read from its source.
|
|
7
|
-
*/
|
|
8
|
-
import 'reflect-metadata'
|
|
9
|
-
|
|
10
|
-
const { existsSync, readFileSync } = require('fs')
|
|
11
|
-
const { join } = require('path')
|
|
12
|
-
const { DataSource } = require('typeorm')
|
|
13
|
-
const { buildSchema } = require('type-graphql')
|
|
14
|
-
const { graphql } = require('graphql')
|
|
15
|
-
|
|
16
|
-
const shell = require('@things-factory/shell')
|
|
17
|
-
const authBase = require('@things-factory/auth-base')
|
|
18
|
-
const contact = require('@things-factory/contact')
|
|
19
|
-
const bizBase = require('@things-factory/biz-base')
|
|
20
|
-
|
|
21
|
-
function loadCompiled(modulePath: string): any {
|
|
22
|
-
const resolved = join(__dirname, '..', 'dist-server', `${modulePath}.js`)
|
|
23
|
-
if (!existsSync(resolved)) {
|
|
24
|
-
throw new Error(`organization build output is missing: ${resolved}\nBuild it first: npm run build:server`)
|
|
25
|
-
}
|
|
26
|
-
return require(resolved)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let dataSource: any
|
|
30
|
-
let organization: any
|
|
31
|
-
let schema: any
|
|
32
|
-
let domain: any
|
|
33
|
-
|
|
34
|
-
const ROWS = `
|
|
35
|
-
summary skills updatedAt employeeId
|
|
36
|
-
educations { school major degree startedOn endedOn }
|
|
37
|
-
certificates { name issuer acquiredOn }
|
|
38
|
-
careers { company department position startedOn endedOn duties }
|
|
39
|
-
projects { name client startedOn endedOn role duties technologies }
|
|
40
|
-
`
|
|
41
|
-
const MINE = `query { myEmployeeProfile { ${ROWS} } }`
|
|
42
|
-
const SAVE = `mutation ($profile: EmployeeProfileInput!) { saveMyEmployeeProfile(profile: $profile) { ${ROWS} } }`
|
|
43
|
-
const LIST = `query { employeeProfiles { employeeId name departmentName jobPosition jobResponsibility hiredOn profile { summary skills } } }`
|
|
44
|
-
|
|
45
|
-
beforeAll(async () => {
|
|
46
|
-
organization = loadCompiled('service/index')
|
|
47
|
-
const { resolvers } = loadCompiled('service/employee-profile/index')
|
|
48
|
-
dataSource = new DataSource({
|
|
49
|
-
type: 'sqlite',
|
|
50
|
-
database: ':memory:',
|
|
51
|
-
synchronize: true,
|
|
52
|
-
dropSchema: true,
|
|
53
|
-
namingStrategy: new shell.NamingStrategy(),
|
|
54
|
-
entities: [...shell.entities, ...authBase.entities, ...bizBase.entities, ...contact.entities, ...organization.entities],
|
|
55
|
-
logging: false
|
|
56
|
-
})
|
|
57
|
-
await dataSource.initialize()
|
|
58
|
-
shell.addDataSource('default', dataSource)
|
|
59
|
-
shell.addDataSource('tx', dataSource)
|
|
60
|
-
schema = await buildSchema({ resolvers, validate: false })
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
beforeEach(async () => {
|
|
64
|
-
await dataSource.synchronize(true)
|
|
65
|
-
domain = await dataSource.getRepository(shell.Domain).save({ name: 'profile', subdomain: 'profile' })
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
afterAll(async () => {
|
|
69
|
-
if (!dataSource) return
|
|
70
|
-
shell.removeDataSource('default')
|
|
71
|
-
shell.removeDataSource('tx')
|
|
72
|
-
await dataSource.destroy()
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
async function person(name: string, employee: Record<string, unknown> | null = {}) {
|
|
76
|
-
const user = await dataSource.getRepository(authBase.User).save({ name, email: `${name}@profile.test` })
|
|
77
|
-
if (employee) {
|
|
78
|
-
const department = (await dataSource.getRepository(organization.Department).findOneBy({ name: '개발팀' })) ?? (await dataSource.getRepository(organization.Department).save({ domain, controlNo: 'D-1', name: '개발팀' }))
|
|
79
|
-
await dataSource.getRepository(organization.Employee).save({ domain, controlNo: name, name, user, department, active: true, ...employee })
|
|
80
|
-
}
|
|
81
|
-
return user
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function ask(user: any, source: string, variableValues?: any) {
|
|
85
|
-
const result = await graphql({ schema, source, variableValues, contextValue: { state: { domain, user, tx: dataSource.manager }, t: (key: string) => key } })
|
|
86
|
-
return result
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
describe("an employee's own profile", () => {
|
|
90
|
-
it('★ an account not linked to an employee has none, and cannot write one', async () => {
|
|
91
|
-
const stranger = await person('stranger', null)
|
|
92
|
-
expect((await ask(stranger, MINE)).data.myEmployeeProfile).toBeNull()
|
|
93
|
-
const refused = await ask(stranger, SAVE, { profile: { summary: 'x' } })
|
|
94
|
-
expect(refused.errors?.[0]?.extensions?.requires).toBe('no-employee')
|
|
95
|
-
expect(await dataSource.getRepository(organization.EmployeeProfile).count()).toBe(0)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('★ is written whole and read back; writing again replaces it, one profile per employee', async () => {
|
|
99
|
-
const kim = await person('kim')
|
|
100
|
-
expect((await ask(kim, MINE)).data.myEmployeeProfile).toBeNull()
|
|
101
|
-
|
|
102
|
-
const first = await ask(kim, SAVE, {
|
|
103
|
-
profile: {
|
|
104
|
-
summary: ' MES 10년 ',
|
|
105
|
-
skills: ['TypeScript', 'TypeScript', 'SQL'],
|
|
106
|
-
educations: [{ school: '서울대', major: '컴퓨터공학', degree: '학사', startedOn: '2005-03', endedOn: '2009-02' }],
|
|
107
|
-
projects: [{ name: '미라텍 MES', client: '미라텍', startedOn: '2024-01', role: 'PM' }, { name: '' }]
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
expect(first.errors).toBeUndefined()
|
|
111
|
-
const mine = (await ask(kim, MINE)).data.myEmployeeProfile
|
|
112
|
-
expect(mine).toMatchObject({
|
|
113
|
-
summary: 'MES 10년',
|
|
114
|
-
skills: ['TypeScript', 'SQL'],
|
|
115
|
-
educations: [{ school: '서울대', major: '컴퓨터공학', degree: '학사', startedOn: '2005-03', endedOn: '2009-02' }],
|
|
116
|
-
certificates: [],
|
|
117
|
-
projects: [{ name: '미라텍 MES', client: '미라텍', startedOn: '2024-01', endedOn: null, role: 'PM', duties: null, technologies: null }]
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
await ask(kim, SAVE, { profile: { summary: '바꿈', certificates: [{ name: '정보처리기사' }] } })
|
|
121
|
-
const again = (await ask(kim, MINE)).data.myEmployeeProfile
|
|
122
|
-
expect(again).toMatchObject({ summary: '바꿈', skills: [], educations: [], certificates: [{ name: '정보처리기사' }], projects: [] })
|
|
123
|
-
expect(await dataSource.getRepository(organization.EmployeeProfile).count()).toBe(1)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('★ read back newest first, as written by its end - the stored rows keep the order written', async () => {
|
|
127
|
-
const lee = await person('lee')
|
|
128
|
-
const saved = await ask(lee, SAVE, {
|
|
129
|
-
profile: {
|
|
130
|
-
projects: [{ name: 'old', startedOn: '2015-01', endedOn: '2016-01' }, { name: 'now', startedOn: '2024-01' }, { name: 'mid', startedOn: '2019-01', endedOn: '2021-06' }]
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
expect(saved.errors).toBeUndefined()
|
|
134
|
-
expect(saved.data.saveMyEmployeeProfile.projects.map((row: any) => row.name)).toEqual(['now', 'mid', 'old'])
|
|
135
|
-
expect((await ask(lee, MINE)).data.myEmployeeProfile.projects.map((row: any) => row.name)).toEqual(['now', 'mid', 'old'])
|
|
136
|
-
const [stored] = await dataSource.query(`SELECT projects FROM employee_profiles WHERE deleted_at IS NULL ORDER BY updated_at DESC LIMIT 1`)
|
|
137
|
-
expect(JSON.parse(stored.projects).map((row: any) => row.name)).toEqual(['old', 'now', 'mid'])
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
it('★ adding from a résumé takes nothing away, and reaches only one\'s own', async () => {
|
|
141
|
-
const kim = await person('kim')
|
|
142
|
-
const park = await person('park')
|
|
143
|
-
await ask(park, SAVE, { profile: { summary: 'park' } })
|
|
144
|
-
await ask(kim, SAVE, { profile: { summary: '옛 요약', skills: ['TypeScript'], projects: [{ name: 'A' }] } })
|
|
145
|
-
const ADD = `mutation ($profile: EmployeeProfileInput!) { addToMyEmployeeProfile(profile: $profile) { ${ROWS} } }`
|
|
146
|
-
const added = await ask(kim, ADD, { profile: { skills: ['typescript', 'PLC'], projects: [{ name: 'A' }, { name: 'B', role: 'PM' }] } })
|
|
147
|
-
expect(added.errors).toBeUndefined()
|
|
148
|
-
expect(added.data.addToMyEmployeeProfile).toMatchObject({ summary: '옛 요약', skills: ['TypeScript', 'PLC'], projects: [{ name: 'A' }, { name: 'B', role: 'PM' }] })
|
|
149
|
-
expect((await ask(park, MINE)).data.myEmployeeProfile.summary).toBe('park')
|
|
150
|
-
const stranger = await person('stranger', null)
|
|
151
|
-
expect((await ask(stranger, ADD, { profile: { summary: 'x' } })).errors?.[0]?.extensions?.requires).toBe('no-employee')
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
it("★ one employee's save never touches another's profile", async () => {
|
|
155
|
-
const kim = await person('kim')
|
|
156
|
-
const park = await person('park')
|
|
157
|
-
await ask(kim, SAVE, { profile: { summary: 'kim' } })
|
|
158
|
-
await ask(park, SAVE, { profile: { summary: 'park' } })
|
|
159
|
-
expect((await ask(kim, MINE)).data.myEmployeeProfile.summary).toBe('kim')
|
|
160
|
-
expect((await ask(park, MINE)).data.myEmployeeProfile.summary).toBe('park')
|
|
161
|
-
expect(await dataSource.getRepository(organization.EmployeeProfile).count()).toBe(2)
|
|
162
|
-
})
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
describe('the profiles of every active employee', () => {
|
|
166
|
-
it('★ lists each active employee with the basics and their profile, empty when none was written', async () => {
|
|
167
|
-
const kim = await person('kim', { jobPosition: '과장', jobResponsibility: '팀장', hiredOn: '2020-03-02' })
|
|
168
|
-
await person('lee')
|
|
169
|
-
await person('gone', { retiredOn: '2020-01-01' })
|
|
170
|
-
await person('off', { active: false })
|
|
171
|
-
await ask(kim, SAVE, { profile: { summary: 'S', skills: ['A'] } })
|
|
172
|
-
|
|
173
|
-
const list = await ask(kim, LIST)
|
|
174
|
-
expect(list.errors).toBeUndefined()
|
|
175
|
-
expect(list.data.employeeProfiles.map((one: any) => [one.name, one.departmentName, one.profile?.summary ?? null])).toEqual([
|
|
176
|
-
['kim', '개발팀', 'S'],
|
|
177
|
-
['lee', '개발팀', null]
|
|
178
|
-
])
|
|
179
|
-
expect(list.data.employeeProfiles[0]).toMatchObject({ jobPosition: '과장', jobResponsibility: '팀장', hiredOn: '2020-03-02', profile: { skills: ['A'] } })
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
it('★ the document of the chosen: active ones only, in the order chosen, as an Excel workbook', async () => {
|
|
183
|
-
const kim = await person('kim')
|
|
184
|
-
await person('lee')
|
|
185
|
-
await person('gone', { retiredOn: '2020-01-01' })
|
|
186
|
-
const ids = (await ask(kim, LIST)).data.employeeProfiles.map((one: any) => one.employeeId)
|
|
187
|
-
const goneId = (await dataSource.getRepository(organization.Employee).findOneBy({ name: 'gone' })).id
|
|
188
|
-
const answer = await ask(kim, `query ($ids: [String!]!) { employeeProfileDocument(employeeIds: $ids, format: XLSX) { fileName mimeType content } }`, { ids: [ids[1], goneId, ids[0]] })
|
|
189
|
-
expect(answer.errors).toBeUndefined()
|
|
190
|
-
const file = answer.data.employeeProfileDocument
|
|
191
|
-
expect(file.fileName).toMatch(/^text\.employee-profile-file-\d{8}\.xlsx$/)
|
|
192
|
-
expect(file.mimeType).toBe('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
|
193
|
-
const { Workbook } = require('exceljs')
|
|
194
|
-
const book = new Workbook()
|
|
195
|
-
await book.xlsx.load(Buffer.from(file.content, 'base64'))
|
|
196
|
-
expect(book.worksheets.map((sheet: any) => sheet.name)).toEqual(['Text.employee-profile-doc-roste', 'lee', 'kim'])
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
it('the preview is an HTML page of the same people', async () => {
|
|
200
|
-
const kim = await person('kim')
|
|
201
|
-
const ids = (await ask(kim, LIST)).data.employeeProfiles.map((one: any) => one.employeeId)
|
|
202
|
-
const answer = await ask(kim, `query ($ids: [String!]!) { employeeProfileDocument(employeeIds: $ids, format: HTML) { fileName mimeType content } }`, { ids })
|
|
203
|
-
expect(answer.errors).toBeUndefined()
|
|
204
|
-
const file = answer.data.employeeProfileDocument
|
|
205
|
-
expect(file.mimeType).toBe('text/html')
|
|
206
|
-
expect(file.fileName).toMatch(/\.html$/)
|
|
207
|
-
expect(Buffer.from(file.content, 'base64').toString('utf8')).toContain('<td class="name" colspan="6">kim</td>')
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
it("★ the document's own words follow the language asked for - one the application runs - or the reader's", () => {
|
|
211
|
-
const { documentTranslator } = loadCompiled('service/employee-profile/employee-profile-query')
|
|
212
|
-
const env = require('@things-factory/env')
|
|
213
|
-
const runs = jest.spyOn(env.config, 'get').mockImplementation((key: string, fallback: any) => (key === 'i18n/languages' ? [{ code: 'ko-KR' }, { code: 'en-US' }] : fallback))
|
|
214
|
-
try {
|
|
215
|
-
const context = { t: (key: string) => `reader:${key}`, i18next: { getFixedT: (lng: string) => (key: string) => `${lng}:${key}` } }
|
|
216
|
-
expect(documentTranslator(context, null)('text.employee-profile-doc-title')).toBe('reader:text.employee-profile-doc-title')
|
|
217
|
-
expect(documentTranslator(context, 'en-US')('text.employee-profile-doc-title')).toBe('en-US:text.employee-profile-doc-title')
|
|
218
|
-
expect(() => documentTranslator(context, 'fr-FR')).toThrow('does not run the language "fr-FR"')
|
|
219
|
-
} finally {
|
|
220
|
-
runs.mockRestore()
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
it('★ reaching a profile does not reach the employee record behind it', () => {
|
|
225
|
-
const type = schema.getType('EmployeeProfile').getFields()
|
|
226
|
-
expect(Object.keys(type)).not.toContain('employee')
|
|
227
|
-
expect(Object.keys(type)).not.toContain('creator')
|
|
228
|
-
expect(Object.keys(schema.getType('EmployeeWithProfile').getFields()).sort()).toEqual(
|
|
229
|
-
['controlNo', 'departmentName', 'employeeId', 'hiredOn', 'jobPosition', 'jobResponsibility', 'name', 'profile'].sort()
|
|
230
|
-
)
|
|
231
|
-
})
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
describe('what each door asks', () => {
|
|
235
|
-
const source = (file: string) => readFileSync(join(__dirname, '..', 'server', 'service', 'employee-profile', file), 'utf8')
|
|
236
|
-
const asks = (text: string, door: string) => {
|
|
237
|
-
const before = text.slice(0, text.indexOf(`async ${door}(`))
|
|
238
|
-
return before.slice(before.lastIndexOf('@Directive(\'@privilege')).match(/category: "([a-z-]+)", privilege: "(\w+)", domainOwnerGranted: (\w+)/)?.slice(1)
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
it('★ one\'s own under employee-self, everyone\'s under employee-profile - and no door writes another\'s', () => {
|
|
242
|
-
expect(asks(source('employee-profile-query.ts'), 'myEmployeeProfile')).toEqual(['employee-self', 'query', 'true'])
|
|
243
|
-
expect(asks(source('employee-profile-query.ts'), 'employeeProfiles')).toEqual(['employee-profile', 'query', 'true'])
|
|
244
|
-
const mutation = source('employee-profile-mutation.ts')
|
|
245
|
-
/* Two doors write - saving the whole and adding from a résumé - and each finds the profile from the caller alone. */
|
|
246
|
-
expect([...mutation.matchAll(/@Mutation\(/g)]).toHaveLength(2)
|
|
247
|
-
for (const door of ['saveMyEmployeeProfile', 'addToMyEmployeeProfile']) {
|
|
248
|
-
expect(asks(mutation, door)).toEqual(['employee-self', 'mutation', 'true'])
|
|
249
|
-
const body = mutation.slice(mutation.indexOf(`async ${door}(`)).split('\n }')[0]
|
|
250
|
-
expect(body).toMatch(/requireMyEmployee\(context\)/)
|
|
251
|
-
expect(body).not.toMatch(/@Arg\('(employee|employeeId|user|userId)'/)
|
|
252
|
-
}
|
|
253
|
-
expect([...mutation.matchAll(/@Directive\('@transaction'\)\n @Directive\('@privilege\(category: "employee-self", privilege: "mutation"/g)]).toHaveLength(2)
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
it('★ the tasks grant them: own-profile to write one\'s own, profiles-reading to read everyone\'s', () => {
|
|
257
|
-
const { ROLE_TASKS } = loadCompiled('role-tasks')
|
|
258
|
-
expect(ROLE_TASKS.find((task: any) => task.id === 'organization.own-profile').grants).toEqual([{ category: 'employee-self', axes: ['query', 'mutation'] }])
|
|
259
|
-
expect(ROLE_TASKS.find((task: any) => task.id === 'organization.profiles-reading').grants).toEqual([{ category: 'employee-profile', axes: ['query'] }])
|
|
260
|
-
})
|
|
261
|
-
})
|