package com.aistudio.bonjuteri.jwlry import com.aistudio.bonjuteri.jwlry.data.CartRepository import com.aistudio.bonjuteri.jwlry.model.Address import com.aistudio.bonjuteri.jwlry.model.CartItem import com.aistudio.bonjuteri.jwlry.model.Order import com.aistudio.bonjuteri.jwlry.model.OrderItem import com.aistudio.bonjuteri.jwlry.model.OrderStatus import com.aistudio.bonjuteri.jwlry.model.PaymentStatus import com.aistudio.bonjuteri.jwlry.model.Product import com.aistudio.bonjuteri.jwlry.model.UserProfile import com.aistudio.bonjuteri.jwlry.model.UserRole import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotEquals import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue import org.junit.Test class BonjuteriBusinessLogicTest { // 1. E-posta ve şifreyle kayıt doğrulamaları @Test fun `test registration validations`() { val emptyFirstName = "" val emptyLastName = "" val invalidEmail = "gecersiz-email" val shortPassword = "123" assertTrue("Ad boş olmamalı", emptyFirstName.isBlank()) assertTrue("Soyad boş olmamalı", emptyLastName.isBlank()) assertFalse("E-posta formatı geçersiz olmalı", invalidEmail.contains("@") && invalidEmail.contains(".")) assertTrue("Şifre en az 6 karakter olmalı", shortPassword.length < 6) val validFirstName = "Ahmet" val validLastName = "Yılmaz" val validEmail = "ahmet@example.com" val validPassword = "password123" assertTrue("Ad geçerli olmalı", validFirstName.isNotBlank()) assertTrue("Soyad geçerli olmalı", validLastName.isNotBlank()) assertTrue("E-posta geçerli olmalı", validEmail.contains("@")) assertTrue("Şifre uzunluğu yeterli olmalı", validPassword.length >= 6) } // 2. Giriş doğrulamaları @Test fun `test sign in validation`() { val blankEmail = " " val blankPass = "" assertTrue("Boş e-posta reddedilmeli", blankEmail.isBlank()) assertTrue("Boş şifre reddedilmeli", blankPass.isBlank()) } // 3. Şifre sıfırlama doğrulaması @Test fun `test password reset email requirement`() { val resetEmail = "info@raappstudio.online" assertTrue("Şifre sıfırlama e-postası boş olamaz", resetEmail.isNotBlank()) assertTrue("Geçerli e-posta formatı", resetEmail.contains("@")) } // 4. Yönetici rolünün doğrulanması (info@raappstudio.online) @Test fun `test super admin account identification and roles`() { val superAdminEmail = "info@raappstudio.online" val superAdminProfile = UserProfile( id = "admin_uid_123", email = superAdminEmail, firstName = "Sistem", lastName = "Yöneticisi", role = UserRole.SUPER_ADMIN.name ) assertEquals(UserRole.SUPER_ADMIN, superAdminProfile.userRole) assertTrue("Süper yönetici yetkili olmalı", superAdminProfile.userRole.isPrivileged) assertTrue("Süper yönetici her şeyi yönetebilmeli", superAdminProfile.userRole.canManageEverything) } // 5. Normal kullanıcının admin paneline erişememesi @Test fun `test normal user cannot access admin privileges`() { val normalUserProfile = UserProfile( id = "user_uid_456", email = "musteri@example.com", firstName = "Ayşe", lastName = "Demir", role = UserRole.USER.name ) assertEquals(UserRole.USER, normalUserProfile.userRole) assertFalse("Normal kullanıcı yetkili olmamalı", normalUserProfile.userRole.isPrivileged) assertFalse("Normal kullanıcı yönetim paneline erişememeli", normalUserProfile.userRole.canManageEverything) } // 6. Editor ve Admin rollerinin yetki kademeleri @Test fun `test editor and admin role hierarchy`() { val editorProfile = UserProfile(id = "editor_1", email = "editor@bonjuteri.com", role = UserRole.EDITOR.name) val adminProfile = UserProfile(id = "admin_1", email = "admin@bonjuteri.com", role = UserRole.ADMIN.name) assertTrue("Editor yetkili olmalı", editorProfile.userRole.isPrivileged) assertFalse("Editor her şeyi yönetememeli", editorProfile.userRole.canManageEverything) assertTrue("Admin yetkili olmalı", adminProfile.userRole.isPrivileged) assertTrue("Admin her şeyi yönetebilmeli", adminProfile.userRole.canManageEverything) } // 7. Ürün ekleme alanlarının doğrulanması @Test fun `test product validation rules`() { // Validation: Ürün adı boş olamaz val blankTitle = " " assertTrue("Ürün adı boş olamaz", blankTitle.isBlank()) // Validation: Satış fiyatı sıfırdan büyük olmalı val invalidPrice = 0.0 val validPrice = 1450.0 assertTrue("Sıfır fiyat geçersiz olmalı", invalidPrice <= 0.0) assertTrue("Pozitif fiyat geçerli olmalı", validPrice > 0.0) // Validation: Stok negatif olmamalı val invalidStock = -1L val validStock = 25L assertTrue("Negatif stok geçersiz", invalidStock < 0L) assertTrue("Pozitif stok geçerli", validStock >= 0L) // Validation: Kategori boş olmamalı val validCategory = "Kolye" assertTrue("Kategori geçerli", validCategory.isNotBlank()) } // 8. Ürün fiyat indirim ve para formatı testleri @Test fun `test product price formatting and discount calculation`() { val product = Product( id = "prod_1", title = "14 Ayar Altın Baget Yüzük", price = 4500.0, oldPrice = 5000.0, stock = 8L, category = "Yüzük" ) assertTrue("Ürün stokta olmalı", product.isInStock) assertTrue("Üründe indirim olmalı", product.hasDiscount) assertEquals(10, product.discountPercent) // (5000 - 4500) / 5000 = %10 assertNotNull(product.formattedPrice) assertNotNull(product.formattedOldPrice) } // 9. Sepet hesaplama ve kargo bedava eşiği testleri @Test fun `test cart calculations and free shipping threshold`() { val item1 = CartItem(id = "1", productId = "p1", title = "Altın Kolye", price = 300.0, quantity = 1L) val item2 = CartItem(id = "2", productId = "p2", title = "Gümüş Küpe", price = 150.0, quantity = 1L) val cart = listOf(item1, item2) val subtotal = cart.sumOf { it.totalPrice } assertEquals(450.0, subtotal, 0.01) val isFreeShippingBeforeThreshold = subtotal >= CartRepository.FREE_SHIPPING_THRESHOLD assertFalse("450 TL için kargo ücretsiz olmamalı", isFreeShippingBeforeThreshold) // Add 1 more item so subtotal >= 500 val item3 = CartItem(id = "3", productId = "p3", title = "Bileklik", price = 100.0, quantity = 1L) val newCart = cart + item3 val newSubtotal = newCart.sumOf { it.totalPrice } assertEquals(550.0, newSubtotal, 0.01) val isFreeShippingAfterThreshold = newSubtotal >= CartRepository.FREE_SHIPPING_THRESHOLD assertTrue("550 TL için kargo ücretsiz olmalı", isFreeShippingAfterThreshold) } // 10. Sipariş oluşturma ve ödeme durumu doğrulaması @Test fun `test order creation and pending payment status integrity`() { val address = Address( id = "addr_1", title = "Evim", fullName = "Ahmet Yılmaz", phone = "05551234567", city = "İstanbul", district = "Kadıköy", neighborhood = "Moda", fullAddress = "Şair Nefi Sk. No:12 D:4" ) val orderItems = listOf( OrderItem(productId = "p1", title = "Pırlanta Yüzük", price = 8500.0, quantity = 1L) ) val order = Order( id = "ord_123", orderNumber = "BNJ-20261012-1001", userId = "user_1", userEmail = "ahmet@example.com", items = orderItems, deliveryAddress = address, subtotal = 8500.0, shippingCost = 0.0, totalAmount = 8500.0, orderStatus = OrderStatus.PREPARING.name, paymentStatus = PaymentStatus.PENDING.name ) assertEquals("BNJ-20261012-1001", order.orderNumber) assertEquals(OrderStatus.PREPARING, order.statusEnum) assertEquals(PaymentStatus.PENDING, order.paymentStatusEnum) assertNotEquals(PaymentStatus.COMPLETED, order.paymentStatusEnum) } // 11. Adres alanlarının tamlığı testi @Test fun `test address fields completeness`() { val validAddress = Address( fullName = "Mehmet Kaya", phone = "05321112233", city = "Ankara", district = "Çankaya", neighborhood = "Kızılay", fullAddress = "Atatürk Bulvarı No: 50" ) assertTrue(validAddress.fullName.isNotBlank()) assertTrue(validAddress.phone.isNotBlank()) assertTrue(validAddress.city.isNotBlank()) assertTrue(validAddress.district.isNotBlank()) assertTrue(validAddress.fullAddress.isNotBlank()) assertTrue(validAddress.fullDisplayAddress.contains("Ankara")) assertTrue(validAddress.fullDisplayAddress.contains("Çankaya")) } }