Anna opens a refund case on the store tablet just before her shift ends. Ben takes over, signs in successfully and sees his own name in the header. Then the receipt Anna requested finishes loading. Whose receipt is now on Ben’s screen?
A sign-in test can pass while the handover still fails. Test the transition with two employees, one device and a piece of unfinished work. The retailer in this example lets both staff members look up stock. Anna, the supervisor, can see and approve refund exceptions. Ben can help customers at the counter. His role gives him no access to the exception record. When Anna signs out, the pending return still belongs to the store.
Track two kinds of state
The server owns case R-17 and its approval status. The client owns the currently displayed receipt, the search field and the request it expects to finish. During a handover, the client can clear those fields immediately. The server can end the departing employee’s session and evaluate later actions under the next employee’s permissions. A receipt response already in flight needs one more check before it can change the screen.
In a FinClip-based deployment, the retailer or its implementation partner builds the employee host app, the Mini Apps and the business services that make these decisions. FinClip supplies the Mini App runtime, development tools and management platform. This example exercises retailer-owned behavior with ordinary JavaScript. FinClip product overview
Save the three JavaScript blocks below, in order, in one file named shift-change.test.mjs. They use the built-in Node.js test runner. Node.js test runner documentation
Give the refund a life beyond the screen
The service fixture has one tablet, one store and one refund. Its sign-in helper represents an already authenticated employee entering a shift. The identifiers stand in for server-managed sessions. The service keeps the employee’s permissions and the refund state in its own memory. The Mini App gets a copy of any record it is allowed to display.
import assert from 'node:assert/strict'
import test from 'node:test'
function makeStore() {
const staff = new Map([['Anna', true], ['Ben', false]])
const sessions = new Map()
const refund = { id: 'R-17', status: 'pending', approvedBy: null }
function employeeFor(session) {
if (!sessions.has(session)) throw new Error('Shift ended')
return sessions.get(session)
}
function refundReviewer(session) {
const employee = employeeFor(session)
if (!staff.get(employee)) throw new Error('Supervisor required')
return employee
}
return {
startShift(employee) {
if (!staff.has(employee)) throw new Error('Unknown employee')
const session = Symbol('shift')
sessions.set(session, employee)
return session
},
endShift(session) {
sessions.delete(session)
},
stock(session, product) {
employeeFor(session)
return product === 'blue lamp' ? 3 : 0
},
readRefund(session) {
refundReviewer(session)
return { ...refund }
},
approveRefund(session) {
const employee = refundReviewer(session)
if (refund.status === 'pending') {
refund.status = 'approved'
refund.approvedBy = employee
}
return { ...refund }
}
}
}
Both refund operations resolve the employee from the session. In the real returns service, the decision might also depend on the amount, store and reason for the exception. Here the approval only records a business decision. It moves no money.
Change employees while a receipt is on its way
The client captures a session before asking for a receipt. When the response arrives, the client checks whether the same session still owns the screen. A fresh session for the same employee also gets a new identity. A lunch break followed by a second sign-in should not give an old request permission to repaint the display.
function makeTablet(store) {
let session
const view = { search: '', receipt: null }
function endShift() {
store.endShift(session)
session = undefined
view.search = ''
view.receipt = null
}
return {
view,
signIn(employee) {
endShift()
session = store.startShift(employee)
},
signOut: endShift,
stock(product) {
const quantity = store.stock(session, product)
view.search = product
return quantity
},
async openRefund(deliver = async value => value) {
const requestedBy = session
const receipt = await deliver(store.readRefund(requestedBy))
if (requestedBy === session) view.receipt = receipt
}
}
}
The deliver argument gives the test control over when an already authorised response reaches the tablet. The real Mini App would await its request. We can now place the shift change between the service reading the record and the screen receiving it, without relying on a timer or a slow network.
Assert what each employee can actually do
test('handover clears the receipt and search, then stock lookup works', async () => {
const store = makeStore()
const tablet = makeTablet(store)
tablet.signIn('Anna')
tablet.stock('red lamp')
await tablet.openRefund()
assert.equal(tablet.view.receipt.id, 'R-17')
tablet.signIn('Ben')
assert.deepEqual(tablet.view, { search: '', receipt: null })
assert.equal(tablet.stock('blue lamp'), 3)
await assert.rejects(tablet.openRefund(), /Supervisor required/)
})
test('a late receipt cannot enter the next employee’s view', async () => {
const tablet = makeTablet(makeStore())
tablet.signIn('Anna')
const delivery = Promise.withResolvers()
const opening = tablet.openRefund(async receipt => {
await delivery.promise
return receipt
})
tablet.signIn('Ben')
delivery.resolve()
await opening
assert.equal(tablet.view.receipt, null)
})
test('an open case survives sign-out and only an authorised shift can approve it', () => {
const store = makeStore()
const morning = store.startShift('Anna')
assert.equal(store.readRefund(morning).status, 'pending')
store.endShift(morning)
const evening = store.startShift('Ben')
assert.throws(() => store.approveRefund(morning), /Shift ended/)
assert.throws(() => store.approveRefund(evening), /Supervisor required/)
store.endShift(evening)
const supervisor = store.startShift('Anna')
assert.equal(store.readRefund(supervisor).status, 'pending')
const approved = { id: 'R-17', status: 'approved', approvedBy: 'Anna' }
assert.deepEqual(store.approveRefund(supervisor), approved)
assert.deepEqual(store.approveRefund(supervisor), approved)
})
Run node --test shift-change.test.mjs with Node.js 24. The first test checks that the tablet is useful to the next employee immediately after cleanup. The second controls delivery order so a stale callback has a chance to run. The last test goes directly to the service and confirms that the failed attempts leave the case pending for an authorised reviewer. Checking the returned status a second time covers a repeated approval against this single in-memory record.
Repeat the handover on the device
In an integration test, keep the same three observations and replace the fixtures with your host’s actual session transition, the Mini App’s real receipt view and a returns service in a test environment. Make the morning receipt distinctive and synthetic so the tester can identify it at a glance. Switch accounts while the request is pending. Inspect the visible page, then reopen the Mini App from the host and check whether it restores the previous employee’s view from storage. Confirm from the service record who approved the final action.
A different failure needs its own test. If Anna submits an approval before signing out, the backend may commit it while the tablet is changing hands. The next authorised reviewer should retrieve the case from the service and see the recorded result. If an approval feeds a payment system, repeat the exercise with the actual business operation identifier and the payment test environment. Inspect the provider’s record to confirm that it issued a single refund.
The service-desk acceptance test can fit on one line. After Ben takes the tablet, he can help the customer find a blue lamp, Anna’s receipt stays off his screen and the store can still account for the return.
Top comments (0)