|
| 1 | +const request = require('supertest'); |
| 2 | +const express = require('express'); |
| 3 | +const app = express(); |
| 4 | +const bodyParser = require('body-parser'); |
| 5 | +const cors = require('cors'); |
| 6 | + |
| 7 | +require('dotenv').config(); |
| 8 | + |
| 9 | +app.use(bodyParser.json()); |
| 10 | +app.use(cors()); |
| 11 | + |
| 12 | +const storyPointRoutes = require('../../routes/storyPointRoutes'); |
| 13 | +app.use('/storypoint', storyPointRoutes); |
| 14 | + |
| 15 | +describe('Story Point Estimation Controller', () => { |
| 16 | + jest.setTimeout(60000); // 60 saniye timeout |
| 17 | + |
| 18 | + // OpenAI API'ye erişim için gerekli ortam değişkenlerini kontrol et |
| 19 | + beforeAll(() => { |
| 20 | + if (!process.env.OPENAI_API_KEY) { |
| 21 | + console.warn('OPENAI_API_KEY ortam değişkeni ayarlanmamış. Test başarısız olabilir.'); |
| 22 | + } |
| 23 | + |
| 24 | + if (!process.env.OPENAI_ASSISTANT_ID) { |
| 25 | + console.warn('OPENAI_ASSISTANT_ID ortam değişkeni ayarlanmamış. Test başarısız olabilir.'); |
| 26 | + } |
| 27 | + }); |
| 28 | + |
| 29 | + test('Bir issue için story point tahmini yapabilmeli', async () => { |
| 30 | + const testData = { |
| 31 | + boardName: 'Test board', |
| 32 | + issueSummary: 'Kullanıcı girişi sayfası oluşturulmalı', |
| 33 | + issueDescription: 'Kullanıcıların sisteme giriş yapabileceği bir sayfa oluşturulmalı. Sayfa email ve şifre alanı içermeli.' |
| 34 | + }; |
| 35 | + |
| 36 | + const response = await request(app) |
| 37 | + .post('/storypoint/estimate') |
| 38 | + .send(testData); |
| 39 | + |
| 40 | + expect(response.status).toBe(200); |
| 41 | + expect(response.body).toHaveProperty('response'); |
| 42 | + expect(response.body).toHaveProperty('threadId'); |
| 43 | + |
| 44 | + console.log('OpenAI yanıtı:', response.body.response); |
| 45 | + |
| 46 | + const responseStr = response.body.response.trim(); |
| 47 | + const isNumeric = /^\d+$/.test(responseStr); |
| 48 | + expect(isNumeric).toBe(true); |
| 49 | + |
| 50 | + const validSPValues = [1, 2, 3, 5, 8, 13]; |
| 51 | + const responseNum = parseInt(responseStr, 10); |
| 52 | + expect(validSPValues.includes(responseNum)).toBe(true); |
| 53 | + |
| 54 | + // Thread ID'yi sakla |
| 55 | + const threadId = response.body.threadId; |
| 56 | + console.log('Thread ID:', threadId); |
| 57 | + |
| 58 | + |
| 59 | + if (threadId) { |
| 60 | + const followUpData = { |
| 61 | + boardName: 'Test board', |
| 62 | + issueSummary: 'Kullanıcı girişi sayfası güncellenmeli', |
| 63 | + issueDescription: 'Mevcut giriş sayfasına şifre sıfırlama özelliği eklenmeli.', |
| 64 | + threadId: threadId |
| 65 | + }; |
| 66 | + |
| 67 | + const followUpResponse = await request(app) |
| 68 | + .post('/storypoint/estimate') |
| 69 | + .send(followUpData); |
| 70 | + |
| 71 | + expect(followUpResponse.status).toBe(200); |
| 72 | + expect(followUpResponse.body).toHaveProperty('response'); |
| 73 | + expect(followUpResponse.body).toHaveProperty('threadId'); |
| 74 | + expect(followUpResponse.body.threadId).toBe(threadId); |
| 75 | + |
| 76 | + console.log('Takip sorusu yanıtı:', followUpResponse.body.response); |
| 77 | + |
| 78 | + const followUpResponseStr = followUpResponse.body.response.trim(); |
| 79 | + const isFollowUpNumeric = /^\d+$/.test(followUpResponseStr); |
| 80 | + expect(isFollowUpNumeric).toBe(true); |
| 81 | + |
| 82 | + const validSPValues = [1, 2, 3, 5, 8, 13]; |
| 83 | + const followUpResponseNum = parseInt(followUpResponseStr, 10); |
| 84 | + expect(validSPValues.includes(followUpResponseNum)).toBe(true); |
| 85 | + } |
| 86 | + }); |
| 87 | + |
| 88 | +}); |
0 commit comments