ekomat-mobilnoe-prilozhenie/test/flow.js

21 lines
989 B
JavaScript

import { randomUUID } from 'node:crypto'
export function visitor(app, suffix = '78') {
const { challengeId, mockOtp } = app.request('POST', '/v1/auth/otp/request', { phone: '+770123456' + suffix })
const { token } = app.request('POST', '/v1/auth/otp/verify', { challengeId, otp: mockOtp, accepted: true })
const headers = { authorization: 'Bearer ' + token }
return {
get: (path) => app.request('GET', '/v1/' + path, {}, headers),
post: (path, payload = {}, key = randomUUID()) => app.request('POST', '/v1/' + path, payload,
{ ...headers, 'idempotency-key': key })
}
}
export function deposit(client, materials) {
client.post('machines/pair', { scanToken: 'ekomat:demo:garden' })
const { session } = client.post('intake-sessions')
const events = 'intake-sessions/' + session.id + '/mock-event'
for (const material of materials) client.post(events, { eventId: randomUUID(), material })
client.post(events, { eventId: randomUUID(), material: 'close' })
}