Skip to content

Commit

Permalink
update typeorm dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed Oct 24, 2024
1 parent d59fb7b commit cdda792
Show file tree
Hide file tree
Showing 3 changed files with 883 additions and 286 deletions.
120 changes: 62 additions & 58 deletions packages/typeorm/__tests__/mongo.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,83 @@
import { beforeAll, afterAll, test, expect, describe } from 'vitest';
import { afterAll, beforeAll, describe, expect, test } from "vitest";

import { session } from 'grammy';
import { Column, DataSource, Entity, ObjectIdColumn, ObjectId } from 'typeorm';
import { MongoMemoryServer } from 'mongodb-memory-server';
import { session } from "grammy";
import { Column, DataSource, Entity, ObjectId, ObjectIdColumn } from "typeorm";
import { MongoMemoryServer } from "mongodb-memory-server";

import { ISession, TypeormAdapter } from '../src';
import { ISession, TypeormAdapter } from "../src";

import { createBot, createMessage } from '@grammyjs/storage-utils';
import { createBot, createMessage } from "@grammyjs/storage-utils";

@Entity()
export class Session implements ISession {
@ObjectIdColumn()
id: ObjectId;
@ObjectIdColumn()
id: ObjectId;

@Column({ type: 'string' })
key: string;
@Column({ type: "string" })
key: string;

@Column({ type: 'string' })
value: string;
@Column({ type: "string" })
value: string;
}

let mongod: MongoMemoryServer;
let source: DataSource;

beforeAll(async () => {
mongod = await MongoMemoryServer.create();
mongod = await MongoMemoryServer.create();

source = await new DataSource({
type: 'mongodb',
url: mongod.getUri(),
entities: [Session],
}).initialize();
source = await new DataSource({
type: "mongodb",
url: mongod.getUri(),
entities: [Session],
}).initialize();
});

afterAll(async () => {
await source.destroy();
await mongod.stop();
await source?.destroy();
await mongod?.stop();
});

describe('Pizza counter test', () => {
test('Pizza counter should be equals 0 on initial', async () => {
const bot = createBot();
const ctx = createMessage(bot);

bot.use(session({
initial() {
return { pizzaCount: 0 };
},
storage: new TypeormAdapter({ repository: source.getRepository(Session) }),
}));

await bot.handleUpdate(ctx.update);

bot.on('msg:text', (ctx) => {
expect(ctx.session.pizzaCount).toEqual(0);
});
});

test('Pizza counter should be equals 1 after first message', async () => {
const bot = createBot();

bot.use(session({
initial: () => ({ pizzaCount: 0 }),
storage: new TypeormAdapter({ repository: source.getRepository(Session) }),
}));

bot.hears('first', (ctx) => {
ctx.session.pizzaCount = Number(ctx.session.pizzaCount) + 1;
});

bot.hears('second', (ctx) => {
expect(ctx.session.pizzaCount).toEqual(1);
});

await bot.handleUpdate(createMessage(bot, 'first').update);
await bot.handleUpdate(createMessage(bot, 'second').update);
});
describe("Pizza counter test", () => {
test("Pizza counter should be equals 0 on initial", async () => {
const bot = createBot();
const ctx = createMessage(bot);

bot.use(session({
initial() {
return { pizzaCount: 0 };
},
storage: new TypeormAdapter({
repository: source.getRepository(Session),
}),
}));

await bot.handleUpdate(ctx.update);

bot.on("msg:text", (ctx) => {
expect(ctx.session.pizzaCount).toEqual(0);
});
});

test("Pizza counter should be equals 1 after first message", async () => {
const bot = createBot();

bot.use(session({
initial: () => ({ pizzaCount: 0 }),
storage: new TypeormAdapter({
repository: source.getRepository(Session),
}),
}));

bot.hears("first", (ctx) => {
ctx.session.pizzaCount = Number(ctx.session.pizzaCount) + 1;
});

bot.hears("second", (ctx) => {
expect(ctx.session.pizzaCount).toEqual(1);
});

await bot.handleUpdate(createMessage(bot, "first").update);
await bot.handleUpdate(createMessage(bot, "second").update);
});
});
20 changes: 11 additions & 9 deletions packages/typeorm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
"LICENSE"
],
"scripts": {
"test:deno": "echo \"Error: no tests found\"",
"test": "vitest",
"start": "node dist/index.js",
"dev": "nodemon",
"debug": "node --inspect=0.0.0.0:9229 --nolazy ./dist/index.js",
"prebuild": "rimraf dist",
"build": "tsc -p tsconfig.build.json",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path ."
Expand All @@ -33,13 +31,17 @@
"homepage": "https://github.com/grammyjs/storages/tree/main/packages/typeorm#readme",
"devDependencies": {
"@grammyjs/storage-utils": "workspace:*",
"better-sqlite3": "^9.4.3",
"grammy": "^1.21.1",
"mongodb": "^6.3.0",
"mongodb-memory-server": "^9.1.6",
"better-sqlite3": "^11.5.0",
"grammy": "^1.30.0",
"mongodb": "^6.10.0",
"mongodb-memory-server": "^10.1.2",
"typeorm": "^0.3.20",
"vite": "^5.1.4",
"vitest": "^1.3.1"
"vite": "^5.4.10",
"vitest": "^2.1.3"
},
"gitHead": "a7758c4f957f103a14832088c6858d693c444576"
"gitHead": "a7758c4f957f103a14832088c6858d693c444576",
"peerDependencies": {
"grammy": "^1.30.0",
"typeorm": "^0.3.20"
}
}
Loading

0 comments on commit cdda792

Please sign in to comment.