@things-factory/auth-base 10.1.254 → 10.1.256
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/dist-server/service/audit/audit-work.d.ts +23 -0
- package/dist-server/service/audit/audit-work.js +43 -0
- package/dist-server/service/audit/audit-work.js.map +1 -0
- package/dist-server/service/index.d.ts +1 -0
- package/dist-server/service/index.js +5 -1
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/tests/audit-work.test.ts +58 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/auth-base",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.256",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"passport-jwt": "^4.0.0",
|
|
51
51
|
"passport-local": "^1.0.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "2fd641697190ce6e87bcf454a60b2321553e8110"
|
|
54
54
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work done through the doors (ADR-0185 decision 6) - read from the audit: a declared mutation that went through is a
|
|
3
|
+
* piece of the person's work on that day; an undeclared one, a failed one, another person's or another day's is not.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { authDataSource, closeAuthDatabase, Domain, getRepository, openAuthDatabase, resetAuthDatabase } from './db'
|
|
7
|
+
import { loadCompiled } from './compiled'
|
|
8
|
+
|
|
9
|
+
const { registerWorkDoors, workDoneBy } = loadCompiled('service/audit/audit-work')
|
|
10
|
+
const { AuditAction } = loadCompiled('service/audit/audit-action')
|
|
11
|
+
const { AuditRequest } = loadCompiled('service/audit/audit-request')
|
|
12
|
+
const { User } = loadCompiled('service/user/user')
|
|
13
|
+
|
|
14
|
+
let domain: any, kim: any, lee: any
|
|
15
|
+
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
await openAuthDatabase()
|
|
18
|
+
})
|
|
19
|
+
afterAll(async () => {
|
|
20
|
+
await closeAuthDatabase()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
await resetAuthDatabase()
|
|
25
|
+
domain = await getRepository(Domain).save({ name: 'work', subdomain: 'work' })
|
|
26
|
+
kim = await getRepository(User).save({ name: 'kim', email: 'kim@work.test', status: 'activated' })
|
|
27
|
+
lee = await getRepository(User).save({ name: 'lee', email: 'lee@work.test', status: 'activated' })
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const request = async (actor: any, at: string, fields: string, outcome: 'ok' | 'error' | 'both' | null, operationType = 'mutation') => {
|
|
31
|
+
const one = await getRepository(AuditRequest).save({ id: require('crypto').randomUUID(), domain, actor, createdAt: new Date(at), channel: 'graphql', operationType, fields })
|
|
32
|
+
for (const each of outcome === 'both' ? ['ok', 'error'] : outcome ? [outcome] : [])
|
|
33
|
+
await getRepository(AuditAction).save({ domain, actor, requestId: one.id, createdAt: new Date(at), kind: 'door.result', door: 'office:mutation', outcome: each })
|
|
34
|
+
return one
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
it('a declared mutation that went through is a piece of work, once per request and work', async () => {
|
|
38
|
+
registerWorkDoors([
|
|
39
|
+
{ work: 'work.office.bank-lines', fields: ['updateMultipleCashTransaction', 'createCashTransaction'] },
|
|
40
|
+
{ work: 'work.office.tax-invoices', fields: ['importOfficeTaxInvoices'] }
|
|
41
|
+
])
|
|
42
|
+
expect(() => registerWorkDoors([{ work: 'work.other', fields: ['importOfficeTaxInvoices'] }])).toThrow(/declared as the work/)
|
|
43
|
+
|
|
44
|
+
await request(kim, '2026-11-10T01:00:00Z', 'updateMultipleCashTransaction,createCashTransaction', 'ok')
|
|
45
|
+
await request(kim, '2026-11-10T02:00:00Z', 'importOfficeTaxInvoices', 'ok')
|
|
46
|
+
await request(kim, '2026-11-10T03:00:00Z', 'importOfficeTaxInvoices', 'error')
|
|
47
|
+
await request(kim, '2026-11-10T03:30:00Z', 'createCashTransaction,importOfficeTaxInvoices', 'both')
|
|
48
|
+
await request(kim, '2026-11-10T04:00:00Z', 'saveMyDraft', 'ok')
|
|
49
|
+
await request(kim, '2026-11-10T05:00:00Z', 'importOfficeTaxInvoices', 'ok', 'query')
|
|
50
|
+
await request(lee, '2026-11-10T06:00:00Z', 'importOfficeTaxInvoices', 'ok')
|
|
51
|
+
await request(kim, '2026-11-17T01:00:00Z', 'importOfficeTaxInvoices', 'ok')
|
|
52
|
+
|
|
53
|
+
const done = await workDoneBy(authDataSource().manager, domain, kim.id, new Date('2026-11-09T00:00:00Z'), new Date('2026-11-16T00:00:00Z'))
|
|
54
|
+
expect(done.map((one: any) => [one.at.toISOString(), one.work])).toEqual([
|
|
55
|
+
['2026-11-10T01:00:00.000Z', 'work.office.bank-lines'],
|
|
56
|
+
['2026-11-10T02:00:00.000Z', 'work.office.tax-invoices']
|
|
57
|
+
])
|
|
58
|
+
})
|