fjffk简单的咖啡店科开发2方法2 环滁皆山也。其西南诸峰,林壑尤美,望之蔚然而深秀者,琅琊也。山行六七里,渐闻水声潺潺,而泻出于两峰之间者,酿泉也 ??????????????????????????????? ??????????????/????????????????? ............/................... .........................../... ??????????????????????????????? >>>>>>>>>>>>>/>>>>>>>>>>>>>>>>> ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>/>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> dsdfhome/nectalco/public_html/tests/Feature/Entity/EntityManagerTest.php000064400000023264152666364230021743 0ustar00create(); SettingTwo::factory()->create(); $this->fullCount = count(EngineEnum::cases()) + count(EntityEnum::listableCases()); }); function mockDefaultModelsCount($type): int { $engines = EngineEnum::cases(); $count = 0; foreach ($engines as $engine) { $engineDefaultModels = $engine->getDefaultModels(Setting::getCache(), SettingTwo::getCache()); $filteredCollection = collect($engineDefaultModels) ->map(function ($entity) { return Entity::driver($entity); // Adjust if `Entity::driver()` isn't static }) ->filter(fn (EntityDriverInterface $driver) => $driver instanceof $type); $count += $filteredCollection->count(); } return $count; } test('total default models credits for current user', function ($increase, $type) { $user = loginAsUser(); $this->seed([ EntitySeeder::class, EngineSeeder::class, ]); $stats = EntityStats::type($type) ->includeDisabled(true) ->includeUnlisted(! $increase); $stats->list() ->each(function (WithCreditInterface $entity) use ($increase, $user) { $this->assertEquals($user->id, $entity->getUser()->id); if ($increase) { $entity->increaseCredit(1.5); } else { $entity->setCredit(1.5); } }); expect($stats->totalCredits())->toBe(mockDefaultModelsCount($type) * 1.5); })->with('bool')->with([ WithCharsInterface::class, WithMinuteInterface::class, WithSecondInterface::class, WithPresentationInterface::class, WithImagesInterface::class, WithImageToVideoInterface::class, WithWordsInterface::class, WithSpeechToTextInterface::class, WithTextToSpeechInterface::class, WithVisionPreviewInterface::class, WithTextToVideoInterface::class, WithPlagiarismInterface::class, ]); test('default schema of user credits', function () { $enginesWithCredits = User::getFreshCredits(); expect($enginesWithCredits) ->toHaveCount(count(EngineEnum::cases())) // Ensure first-level count only ->each(function ($entities) { $entities->each(function ($entity) { $entity ->toBeArray() // Assert that $entity is an array ->toHaveKeys(['credit', 'isUnlimited']) // Check that it has the expected keys ->toHaveKey('credit', 0) // Check that 'credit' is 0 ->toHaveKey('isUnlimited', false); // Check that 'isUnlimited' is false }); }); }); test('default schema from user credits', function () { $creditModel = User::factory()->create([ 'entity_credits' => null, ]); expect($creditModel->entity_credits) ->toBeArray() ->not ->toBeEmpty() ->toHaveCount(count(EngineEnum::cases())); assertExpectedCreditsSize($creditModel->entity_credits, $this->fullCount); }); test('updated schema with missing models from user credits', function () { $creditModel = User::factory()->create(); $enginesFirstLevelCount = count(EngineEnum::cases()); $listableCasesCount = count(EntityEnum::listableCases()); $fullCount = $enginesFirstLevelCount + $listableCasesCount; expect($creditModel->entity_credits) ->toHaveCount($enginesFirstLevelCount) ->toHaveKey(EntityEnum::GPT_4_O->engine()->slug()); assertExpectedCreditsSize($creditModel->entity_credits, $fullCount); // retrun array not collection $enginesWithEntitiesWithoutGPT40Entity = collect($creditModel->entity_credits) ->map(function ($entities, $engine) { if ($engine === EntityEnum::GPT_4_O->engine()->slug()) { return collect($entities) ->filter(function ($entity, $key) { return $key !== EntityEnum::GPT_4_O->slug(); }); } return $entities; })->toArray(); expect($enginesWithEntitiesWithoutGPT40Entity) ->toHaveCount($enginesFirstLevelCount) ->toHaveKey(EntityEnum::GPT_4_O->engine()->slug()) ->and($enginesWithEntitiesWithoutGPT40Entity[EntityEnum::GPT_4_O->engine()->slug()])->not->toHaveKey(EntityEnum::GPT_4_O->slug()); assertExpectedCreditsSize($enginesWithEntitiesWithoutGPT40Entity, $fullCount - 1); $creditModel->update([ 'entity_credits' => $enginesWithEntitiesWithoutGPT40Entity, ]); // refresh the model $newModelCredits = $creditModel->refresh()->entity_credits; expect($newModelCredits) ->toHaveCount($enginesFirstLevelCount) ->toHaveKey(EntityEnum::GPT_4_O->engine()->slug()); assertExpectedCreditsSize($newModelCredits, $fullCount); }); test('total default models credits for specific user', function ($increase, $type) { $user = User::factory()->create(); $this->seed([ EntitySeeder::class, EngineSeeder::class, ]); $stats = EntityStats::type($type) ->includeDisabled(true) ->includeUnlisted(! $increase) ->forUser($user); $stats->list() ->each(function (WithCreditInterface $entity) use ($increase, $user) { $this->assertEquals($user->id, $entity->getUser()->id); if ($increase) { $entity->increaseCredit(1.5); } else { $entity->setCredit(1.5); } }); expect($stats->totalCredits())->toBe(mockDefaultModelsCount($type) * 1.5); })->with('bool')->with([ WithImagesInterface::class, WithImageToVideoInterface::class, WithWordsInterface::class, WithSpeechToTextInterface::class, WithTextToSpeechInterface::class, WithVisionPreviewInterface::class, WithTextToVideoInterface::class, WithPlagiarismInterface::class, ]); test('set all image drivers to unlimited', function () { $user = loginAsUser(); $this->seed([ EntitySeeder::class, EngineSeeder::class, ]); $stats = EntityStats::image() ->includeDisabled(true) ->includeUnlisted(true); $stats->list() ->each(function ($entity) { $entity->setAsUnlimited(); }); $stats->list() ->each(function ($entity) { $defaultModels = $entity->engine()->getDefaultModels(Setting::getCache(), SettingTwo::getCache()); if (in_array($entity->enum(), $defaultModels, true)) { $this->assertTrue($entity->isUnlimitedCredit()); } else { $this->assertFalse($entity->isUnlimitedCredit()); } }); }); test('set all image drivers to limited', function () { $user = loginAsUser(); $this->seed([ EntitySeeder::class, EngineSeeder::class, ]); $stats = EntityStats::image() ->includeDisabled(true) ->includeUnlisted(true); $stats->list() ->each(function ($entity) { $entity->setCredit(1.5); $entity->setAsUnlimited(false); }); $stats->list() ->each(function ($entity) { $this->assertFalse($entity->isUnlimitedCredit()); }); }); test('set all word drivers to unlimited', function () { $user = loginAsUser(); $this->seed([ EntitySeeder::class, EngineSeeder::class, ]); $stats = EntityStats::word() ->includeDisabled(true) ->includeUnlisted(true); $stats->list() ->each(function ($entity) { $entity->setAsUnlimited(); }); $stats->list() ->each(function ($entity) { $defaultModels = $entity->engine()->getDefaultModels(Setting::getCache(), SettingTwo::getCache()); if (in_array($entity->enum(), $defaultModels, true)) { $this->assertTrue($entity->isUnlimitedCredit()); } else { $this->assertFalse($entity->isUnlimitedCredit()); } }); }); test('set all word drivers to limited', function () { $user = loginAsUser(); $this->seed([ EntitySeeder::class, EngineSeeder::class, ]); $stats = EntityStats::word() ->includeDisabled(true) ->includeUnlisted(true); $stats->list() ->each(function ($entity) { $entity->setCredit(1.5); $entity->setAsUnlimited(false); }); $stats->list() ->each(function ($entity) { $this->assertFalse($entity->isUnlimitedCredit()); }); });