-
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.
Merge pull request #11 from numengames/refactor/replace-assistant-wit…
…h-aiagent refactor: Replace 'assistant' model with 'AIAgent' model for improved…
- Loading branch information
Showing
9 changed files
with
79 additions
and
73 deletions.
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
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,31 @@ | ||
import mongoose, { Schema, model, Types } from 'mongoose'; | ||
|
||
export interface AIAgentAttributes { | ||
name: string; | ||
provider: string; | ||
createdAt?: Date; | ||
updatedAt?: Date; | ||
aiAgentId: string; | ||
_id?: Types.ObjectId; | ||
apiKeyEnvVar: string; | ||
} | ||
|
||
const baseSchema = new Schema<AIAgentAttributes>( | ||
{ | ||
apiKeyEnvVar: { type: String }, | ||
name: { type: String, required: true }, | ||
provider: { type: String, required: true }, | ||
aiAgentId: { type: String, required: true }, | ||
}, | ||
{ versionKey: false, timestamps: true }, | ||
); | ||
|
||
export const AIAgentModel = | ||
mongoose.models.AIAgent || model<AIAgentAttributes>('AIAgent', baseSchema); | ||
|
||
export const OpenAIAgentModel = AIAgentModel.discriminator( | ||
'OpenAIAgent', | ||
new Schema({}, { discriminatorKey: 'provider' }), | ||
); | ||
|
||
export type AIAgentDocument = ReturnType<(typeof AIAgentModel)['hydrate']>; |
This file was deleted.
Oops, something went wrong.
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
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
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,13 @@ | ||
import { faker } from '@faker-js/faker'; | ||
|
||
import { AIAgentModel } from '../../src/models/ai-agents'; | ||
import { AIAgentAttributes } from '../../src/models/ai-agents'; | ||
|
||
export default (params: Partial<AIAgentAttributes> = {}) => | ||
AIAgentModel.create({ | ||
name: faker.word.words(), | ||
provider: faker.company.name(), | ||
aiAgentId: faker.string.uuid(), | ||
apiKeyEnvVar: faker.internet.password({ length: 24 }), | ||
...params, | ||
}); |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
import { AIAgentDocument } from '../../src/models/ai-agents'; | ||
import { mongoose, AIAgentModel } from '../../src'; | ||
import createAIAgent from '../helpers/create-ai-agent'; | ||
|
||
const testDatabase = require('../test-db')(mongoose); | ||
|
||
describe('AIAgent', () => { | ||
beforeAll(() => testDatabase.connect()); | ||
|
||
afterAll(() => testDatabase.close()); | ||
|
||
describe('cuando se crea un nuevo agente AI', () => { | ||
let aiAgentObject: AIAgentDocument; | ||
|
||
beforeAll(async () => { | ||
aiAgentObject = await createAIAgent(); | ||
}); | ||
|
||
afterAll(() => AIAgentModel.deleteOne({ _id: aiAgentObject.id })); | ||
|
||
test('debería contener todas las propiedades', async () => { | ||
const aiAgentDocument = <AIAgentDocument>await AIAgentModel.findById(aiAgentObject.id); | ||
|
||
expect(aiAgentDocument._id).toBeDefined(); | ||
expect(aiAgentDocument.createdAt).toBeDefined(); | ||
expect(aiAgentDocument.updatedAt).toBeDefined(); | ||
expect(aiAgentDocument.name).toBe(aiAgentObject.name); | ||
expect(aiAgentDocument.provider).toBe(aiAgentObject.provider); | ||
expect(aiAgentDocument.aiAgentId).toBe(aiAgentObject.aiAgentId); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.