getContainer()->get('metadata'); $metadata->set('entityDefs', $entityType, [ 'fields' => $data, ]); $metadata->save(); } public function testRequiredVarchar1() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Account', [ 'name' => [ 'required' => true, ], ]); $this->expectException(BadRequest::class); $app->getContainer()->get('serviceFactory')->create('Account')->create((object) [ 'name' => null, ]); } public function testUpdateRequiredVarchar1() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Account', [ 'name' => [ 'required' => true, ], ]); $entity = $app->getContainer()->get('serviceFactory')->create('Account')->create((object) [ 'name' => 'test' ]); $this->expectException(BadRequest::class); $app->getContainer()->get('serviceFactory')->create('Account')->update($entity->id, (object) [ 'name' => '', ]); } public function testRequiredVarchar2() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Account', [ 'name' => [ 'required' => true, ], ]); $this->expectException(BadRequest::class); $app->getContainer()->get('serviceFactory')->create('Account')->create((object) [ ]); } public function testRequiredVarchar3() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Account', [ 'name' => [ 'required' => true, ], ]); $app->getContainer()->get('serviceFactory')->create('Account')->create((object) [ 'name' => 'test', ]); $this->assertTrue(true); } public function testMaxLength1() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Account', [ 'name' => [ 'required' => true, 'maxLength' => 5, ], ]); $this->expectException(BadRequest::class); $app->getContainer()->get('serviceFactory')->create('Account')->create((object) [ 'name' => '123456', ]); } public function testMaxLength2() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Account', [ 'name' => [ 'required' => true, 'maxLength' => 5, ] ]); $app->getContainer()->get('serviceFactory')->create('Account')->create((object) [ 'name' => '12345', ]); $this->assertTrue(true); } public function testRequiredLink1() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Account', [ 'assignedUser' => [ 'required' => true, ] ]); $this->expectException(BadRequest::class); $app->getContainer()->get('serviceFactory')->create('Account')->create((object) [ 'name' => 'test', 'assignedUserId' => null, ]); } public function testRequiredLink2() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Account', [ 'assignedUser' => [ 'required' => true, ] ]); $app->getContainer()->get('serviceFactory')->create('Account')->create((object) [ 'name' => 'test', 'assignedUserId' => '1', ]); $this->assertTrue(true); } public function testRequiredLinkMultiple1() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Account', [ 'teams' => [ 'required' => true, ] ]); $this->expectException(BadRequest::class); $app->getContainer()->get('serviceFactory')->create('Account')->create((object) [ 'name' => 'test', 'teamsIds' => [], ]); } public function testRequiredCurrency1() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Lead', [ 'opportunityAmount' => [ 'required' => true, ] ]); $this->expectException(BadRequest::class); $app->getContainer()->get('serviceFactory')->create('Lead')->create((object) [ 'lastName' => 'test', 'opportunityAmount' => null, ]); } public function testRequiredCurrency2() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Lead', [ 'opportunityAmount' => [ 'required' => true, ] ]); $app->getContainer()->get('serviceFactory')->create('Lead')->create((object) [ 'lastName' => 'test', 'opportunityAmount' => 100, 'opportunityAmountCurrency' => null, ]); $this->assertTrue(true); } public function testRequiredCurrency3() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Lead', [ 'opportunityAmount' => [ 'required' => true, ] ]); $app->getContainer()->get('serviceFactory')->create('Lead')->create((object) [ 'lastName' => 'test', 'opportunityAmount' => 100, 'opportunityAmountCurrency' => 'USD', ]); $this->assertTrue(true); } public function testRequiredEnum1() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Lead', [ 'status' => [ 'required' => true, 'default' => null, ] ]); $app = $this->createApplication(); $this->expectException(BadRequest::class); $app->getContainer()->get('serviceFactory')->create('Lead')->create((object) [ 'lastName' => 'test', ]); } public function testRequiredEnum2() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Lead', [ 'status' => [ 'required' => true, ] ]); $this->expectException(BadRequest::class); $app->getContainer()->get('serviceFactory')->create('Lead')->create((object) [ 'lastName' => 'test', 'status' => null, ]); } public function testRequiredEnum3() { $app = $this->createApplication(); $this->setFieldsDefs($app, 'Lead', [ 'status' => [ 'required' => true, ] ]); $app->getContainer()->get('serviceFactory')->create('Lead')->create((object) [ 'lastName' => 'test', 'status' => 'New', ]); $this->assertTrue(true); } public function testSkipRequired() { $this->getContainer()->get('serviceFactory')->create('Meeting')->create((object) [ 'name' => 'test', 'dateStart' => '2021-01-01 00:00:00', 'duration' => 1000, 'assignedUserId' => '1', ]); $this->assertTrue(true); } public function testSettings() { /* @var $service SettingsService */ $service = $this->getContainer()->get('serviceFactory')->create('Settings'); $this->expectException(BadRequest::class); $service->setConfigData((object) [ 'activitiesEntityList' => 'should-be-array', ]); } }