mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 10:20:15 +01:00
Move usermethods and models to data-schema
This commit is contained in:
parent
4808c5be48
commit
4049b5572c
93 changed files with 2396 additions and 1267 deletions
|
|
@ -1,8 +1,8 @@
|
|||
const mongoose = require('mongoose');
|
||||
const { MongoMemoryServer } = require('mongodb-memory-server');
|
||||
const { Transaction } = require('./Transaction');
|
||||
const Balance = require('./Balance');
|
||||
const { spendTokens, spendStructuredTokens } = require('./spendTokens');
|
||||
const db = require('~/lib/db/connectDb');
|
||||
const { createTransaction, createAutoRefillTransaction } = require('./Transaction');
|
||||
|
||||
// Mock the logger to prevent console output during tests
|
||||
jest.mock('~/config', () => ({
|
||||
|
|
@ -20,10 +20,15 @@ describe('spendTokens', () => {
|
|||
let mongoServer;
|
||||
let userId;
|
||||
|
||||
let Transaction;
|
||||
let Balance;
|
||||
beforeAll(async () => {
|
||||
mongoServer = await MongoMemoryServer.create();
|
||||
const mongoUri = mongoServer.getUri();
|
||||
await mongoose.connect(mongoUri);
|
||||
await db.connectDb(mongoUri);
|
||||
|
||||
Balance = db.models.Balance;
|
||||
Transaction = db.models.Transaction;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
@ -197,7 +202,7 @@ describe('spendTokens', () => {
|
|||
// Check that the transaction records show the adjusted values
|
||||
const transactionResults = await Promise.all(
|
||||
transactions.map((t) =>
|
||||
Transaction.create({
|
||||
createTransaction({
|
||||
...txData,
|
||||
tokenType: t.tokenType,
|
||||
rawAmount: t.rawAmount,
|
||||
|
|
@ -280,7 +285,7 @@ describe('spendTokens', () => {
|
|||
|
||||
// Check the return values from Transaction.create directly
|
||||
// This is to verify that the incrementValue is not becoming positive
|
||||
const directResult = await Transaction.create({
|
||||
const directResult = await createTransaction({
|
||||
user: userId,
|
||||
conversationId: 'test-convo-3',
|
||||
model: 'gpt-4',
|
||||
|
|
@ -607,7 +612,7 @@ describe('spendTokens', () => {
|
|||
const promises = [];
|
||||
for (let i = 0; i < numberOfRefills; i++) {
|
||||
promises.push(
|
||||
Transaction.createAutoRefillTransaction({
|
||||
createAutoRefillTransaction({
|
||||
user: userId,
|
||||
tokenType: 'credits',
|
||||
context: 'concurrent-refill-test',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue