import { test as bunTest, expect, describe } from "bun:test"; import { generateClient } from "./helper.ts"; import type { PrismaClient } from "./prisma/types.d.ts"; function* TestIDGenerator(): Generator { while (true) { yield Math.floor(1 + Math.random() * 2147483648); } } const test_id = TestIDGenerator(); async function cleanTestId(prisma: PrismaClient, testId: number) { try { await prisma.post.deleteMany({ where: { testId } }); await prisma.user.deleteMany({ where: { testId } }); } catch {} } ["sqlite", "postgres" /*"mssql", "mongodb"*/].forEach(async type => { let Client: typeof PrismaClient; try { Client = await generateClient(type); } catch (err: any) { console.warn(`Skipping ${type} tests, failed to generate/migrate`, err.message); } async function test(label: string, callback: Function, timeout: number = 5000) { const it = Client ? bunTest : bunTest.skip; it( label, async () => { const prisma = new Client(); const currentTestId = test_id.next().value; await cleanTestId(prisma, currentTestId); try { await callback(prisma, currentTestId); } finally { await prisma.$disconnect(); } }, timeout, ); } describe(`prisma ${type}`, () => { test( "CRUD basics", async (prisma: PrismaClient, testId: number) => { const user = await prisma.user.create({ data: { testId, name: "Test", email: "test@oven.sh", }, }); expect(user?.name).toBe("Test"); expect(user?.email).toBe("test@oven.sh"); expect(user?.testId).toBe(testId); const users = await prisma.user.findMany({ where: { testId, name: "Test", }, }); expect(users.length).toBe(1); const updatedUser = await prisma.user.update({ where: { id: user.id, }, data: { name: "Test2", }, }); expect(updatedUser?.name).toBe("Test2"); const deletedUser = await prisma.user.delete({ where: { id: user.id } }); expect(deletedUser?.name).toBe("Test2"); }, 20000, ); test( "CRUD with relations", async (prisma: PrismaClient, testId: number) => { const user = await prisma.user.create({ data: { testId, name: "Test", email: "test@oven.sh", posts: { create: { testId, title: "Hello World", }, }, }, }); expect(user?.name).toBe("Test"); expect(user?.email).toBe("test@oven.sh"); expect(user?.testId).toBe(testId); const usersWithPosts = await prisma.user.findMany({ where: { testId, }, include: { posts: true, }, }); expect(usersWithPosts.length).toBe(1); expect(async () => await prisma.user.deleteMany({ where: { testId } })).toThrow(); const deletedPosts = await prisma.post.deleteMany({ where: { testId } }); expect(deletedPosts?.count).toBe(1); const deletedUser = await prisma.user.deleteMany({ where: { testId } }); expect(deletedUser?.count).toBe(1); }, 20000, ); test( "Should execute multiple commands at the same time", async (prisma: PrismaClient, testId: number) => { const users = await Promise.all( new Array(10).fill(0).map((_, i) => prisma.user.create({ data: { testId, name: `Test${i}`, email: `test${i}@oven.sh`, }, }), ), ); expect(users.length).toBe(10); users.forEach((user, i) => { expect(user?.name).toBe(`Test${i}`); expect(user?.email).toBe(`test${i}@oven.sh`); }); const deletedUser = await prisma.user.deleteMany({ where: { testId } }); expect(deletedUser?.count).toBe(10); }, 20000, ); }); }); alue='1'/>
path: root/macros/src/codegen/software_tasks.rs (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2019-06-13rtfm-syntax refactor + heterogeneous multi-core supportGravatar Jorge Aparicio 1-0/+169
2019-05-21bump heapless dependency to v0.5.0; remove "nightly" featureGravatar Jorge Aparicio 5-136/+57
with the upcoming version of heapless we are able to initialize all internal queues in const context removing the need for late initialization this commit also removes the "nightly" feature because all the optimization provided by it are now enabled by default
2019-05-21remove unused checkGravatar Jorge Aparicio 3-260/+49
that was added in #140 but it's no longer required
2019-05-21removes the maybe_uninit feature gateGravatar Jorge Aparicio 3-51/+21
and stop newtyping `core::mem::MaybeUninit`
2019-05-09generate resource proxies only when neededGravatar Jorge Aparicio 1-29/+32
only `static mut` resources need proxies
2019-05-08document resolution and range of Instant and DurationGravatar Jorge Aparicio 1-0/+31
2019-05-08fix typoGravatar Jorge Aparicio 1-1/+1
2019-05-08write generated code to disk for easier inspectionGravatar Jorge Aparicio 2-1/+74
now that the generated code is actually readable let's make it easier to access this commit also documents how to inspect the generated code via `rtfm-expansion.rs` and `cargo-expand`
2019-05-01document internalsGravatar Jorge Aparicio 10-5/+1767
note that this assumes that RFC #155 has been implemented
2019-05-01book: indirection for faster message passingGravatar Jorge Aparicio 5-3/+128
2019-05-01rtfm::app: update error messageGravatar Jorge Aparicio 1-1/+1
2019-05-01push docs to another repo & update READMEGravatar Jorge Aparicio 2-4/+5
2019-05-01travis: disable builds on stableGravatar Jorge Aparicio 1-6/+6
2019-05-01ci: the singleton example has been removedGravatar Jorge Aparicio 1-8/+0
2019-05-01update the bookGravatar Jorge Aparicio 8-48/+20
2019-05-01test RFC 147Gravatar Jorge Aparicio 5-0/+93
2019-05-01update compile-fail testsGravatar Jorge Aparicio 35-179/+95
2019-05-01update compile-pass testsGravatar Jorge Aparicio 10-212/+107
2019-05-01update examplesGravatar Jorge Aparicio 23-235/+159
2019-05-01implement RFCs 147 and 155, etc.Gravatar Jorge Aparicio 11-2252/+2412
This commit: - Implements RFC 147: "all functions must be safe" - Implements RFC 155: "explicit Context parameter" - Implements the pending breaking change #141: reject assign syntax in `init` (which was used to initialize late resources) - Refactors code generation to make it more readable -- there are no more random identifiers in the output -- and align it with the book description of RTFM internals. - Makes the framework hard depend on `core::mem::MaybeUninit` and thus will require nightly until that API is stabilized. - Fixes a ceiling analysis bug where the priority of the system timer was not considered in the analysis. - Shrinks the size of all the internal queues by turning `AtomicUsize` indices into `AtomicU8`s. - Removes the integration with `owned_singleton`.
2019-04-21bors: do not merge PRs labeled S-blockedGravatar Jorge Aparicio 1-1/+2
2019-04-21v0.4.3Gravatar Jorge Aparicio 4-8/+31