import 'dotenv/config' import { csColumn, csTable } from '@cipherstash/schema' import { beforeAll, describe, expect, it } from 'vitest' import { protect } from '../src' const users = csTable('users', { email: csColumn('email').freeTextSearch().equality().orderAndRange(), address: csColumn('address').freeTextSearch(), json: csColumn('json').dataType('json'), }) let protectClient: Awaited> beforeAll(async () => { protectClient = await protect({ schemas: [users], }) }) describe('encryption and decryption', () => { it('should encrypt and decrypt a payload', async () => { const email = 'hello@example.com' const ciphertext = await protectClient.encrypt(email, { column: users.email, table: users, }) if (ciphertext.failure) { throw new Error(`[protect]: ${ciphertext.failure.message}`) } // Verify encrypted field expect(ciphertext.data).toHaveProperty('c') const a = ciphertext.data const plaintext = await protectClient.decrypt(ciphertext.data) expect(plaintext).toEqual({ data: email, }) }, 30000) })