forked from grammyjs/storages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(prisma): silence the "Record to delete does not exist" error (gra…
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { test, expect, describe, beforeEach } from 'vitest'; | ||
import { session } from 'grammy'; | ||
import { PrismaAdapter } from '../src'; | ||
import { createBot, createMessage } from '@grammyjs/storage-utils'; | ||
import prisma from './helpers/prisma'; | ||
|
||
beforeEach(async () => { | ||
await prisma.session.deleteMany({}); | ||
}); | ||
|
||
describe('Delete test', () => { | ||
test('A not yet stored record should be nullable without throwing', async () => { | ||
const bot = createBot(); | ||
|
||
bot.use( | ||
session({ | ||
initial() { | ||
return { pizzaCount: 0 }; | ||
}, | ||
storage: new PrismaAdapter(prisma.session), | ||
}) | ||
); | ||
|
||
bot.hears('first', (ctx) => { | ||
ctx.session = null; | ||
}); | ||
|
||
bot.hears('second', (ctx) => { | ||
expect(ctx.session).toHaveProperty('pizzaCount'); | ||
}); | ||
|
||
const firstMessage = createMessage(bot, 'first'); | ||
const secondMessage = createMessage(bot, 'second'); | ||
|
||
await bot.handleUpdate(firstMessage.update); | ||
await bot.handleUpdate(secondMessage.update); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters