/** * Copyright (c) 2022 EdgerOS Team. * All rights reserved. * * Detailed license information can be found in the LICENSE file. * * Author : xueqiang * Date : 2024-08-08 17:36:23 * LastEditors : xueqiang * LastEditTime : 2024-08-14 15:43:37 */ import { createTestClientAndKeys, tearDownTestClient } from './util' import { test } from '@edgeros/tapes' import assert from 'assert' test('transactions - runs a simple if', async (t) => { const client = await createTestClientAndKeys() await client.if('foo1', 'Value', '==', 'bar1').then(client.put('foo1').value('bar2')).commit() assert(await client.get('foo1').string(), 'bar2') t.pass('transactions - runs a simple if - SUCCESS') await tearDownTestClient(client) t.end() }) test('transactions - runs consequents', async (t) => { const client = await createTestClientAndKeys() await client .if('foo1', 'Value', '==', 'bar1') .then(client.put('foo1').value('bar2')) .else(client.put('foo1').value('bar3')) .commit() assert(await client.get('foo1').string(), 'bar2') t.pass('transactions - runs consequents - SUCCESS') await tearDownTestClient(client) t.end() }) test('transactions - runs multiple clauses and consequents', async (t) => { const client = await createTestClientAndKeys() const result = await client .if('foo1', 'Value', '==', 'bar1') .and('foo2', 'Value', '==', 'wut') .then(client.put('foo1').value('bar2')) .else(client.put('foo1').value('bar3'), client.get('foo2')) .commit() assert(result.responses[1].response_range.kvs[0].value.toString(), 'bar2') t.pass('transactions - runs multiple clauses and consequents - SUCCESS') await tearDownTestClient(client) t.end() })