|
14 | 14 | use FiveamCode\LaravelNotionApi\Entities\Properties\Number; |
15 | 15 | use FiveamCode\LaravelNotionApi\Entities\Properties\People; |
16 | 16 | use FiveamCode\LaravelNotionApi\Entities\Properties\PhoneNumber; |
| 17 | +use FiveamCode\LaravelNotionApi\Entities\Properties\Relation; |
| 18 | +use FiveamCode\LaravelNotionApi\Entities\Properties\Rollup; |
17 | 19 | use FiveamCode\LaravelNotionApi\Entities\Properties\Select; |
18 | 20 | use FiveamCode\LaravelNotionApi\Entities\Properties\Text; |
19 | 21 | use FiveamCode\LaravelNotionApi\Entities\Properties\Title; |
|
33 | 35 | $this->expectExceptionMessage('Bad Request: (validation_error) (Title is not provided)'); |
34 | 36 | $this->expectExceptionCode(400); |
35 | 37 |
|
36 | | - \Notion::databases() |
| 38 | + Notion::databases() |
37 | 39 | ->build() |
38 | 40 | ->add(PropertyBuilder::checkbox('Test Checkbox')) |
39 | 41 | ->createInPage('0adbc2eb57e84569a700a70d537615be'); |
|
72 | 74 | ->phoneNumber('Test PhoneNumber') |
73 | 75 | ->people('Test People') |
74 | 76 | ->files('Test Files') |
| 77 | + ->relation('Test Relation', '375da18ab01d42d18e95a9dc6a901db1') |
| 78 | + ->rollup('Test Rollup', 'Tag', 'Test Relation', 'unique') |
75 | 79 | ->createdBy('Test Created By') |
76 | 80 | ->createdTime('Test Created Time') |
77 | 81 | ->lastEditedBy('Test Last Edited By') |
78 | 82 | ->lastEditedTime('Test Last Edited Time'); |
79 | 83 |
|
80 | | - $databaseEntity = \Notion::databases() |
| 84 | + $databaseEntity = Notion::databases() |
81 | 85 | ->build() |
82 | 86 | // ->inline() //TODO: Currently not supported due to Notion API versioning |
83 | 87 | ->title('Created By Testing Database') |
|
94 | 98 | expect($databaseEntity->getTitle())->toEqual('Created By Testing Database'); |
95 | 99 | expect($databaseEntity->getParentId())->toEqual('0adbc2eb-57e8-4569-a700-a70d537615be'); |
96 | 100 |
|
97 | | - expect($databaseEntity->getProperties())->toHaveCount(18); |
| 101 | + expect($databaseEntity->getProperties())->toHaveCount(20); |
98 | 102 | expect($databaseEntity->getProperty('Test Title'))->toBeInstanceOf(Title::class); |
99 | 103 | expect($databaseEntity->getProperty('Test Custom RichText'))->toBeInstanceOf(Text::class); |
100 | 104 | expect($databaseEntity->getProperty('Test RichText'))->toBeInstanceOf(Text::class); |
|
109 | 113 | expect($databaseEntity->getProperty('Test PhoneNumber'))->toBeInstanceOf(PhoneNumber::class); |
110 | 114 | expect($databaseEntity->getProperty('Test People'))->toBeInstanceOf(People::class); |
111 | 115 | expect($databaseEntity->getProperty('Test Files'))->toBeInstanceOf(Files::class); |
| 116 | + expect($databaseEntity->getProperty('Test Relation'))->toBeInstanceOf(Relation::class); |
| 117 | + expect($databaseEntity->getProperty('Test Rollup'))->toBeInstanceOf(Rollup::class); |
112 | 118 | expect($databaseEntity->getProperty('Test Created By'))->toBeInstanceOf(CreatedBy::class); |
113 | 119 | expect($databaseEntity->getProperty('Test Created Time'))->toBeInstanceOf(CreatedTime::class); |
114 | 120 | expect($databaseEntity->getProperty('Test Last Edited By'))->toBeInstanceOf(LastEditedBy::class); |
115 | 121 | expect($databaseEntity->getProperty('Test Last Edited Time'))->toBeInstanceOf(LastEditedTime::class); |
116 | 122 |
|
| 123 | + expect($databaseEntity->getProperty('Test Relation')->getRelation()[0])->toBe('375da18a-b01d-42d1-8e95-a9dc6a901db1'); |
| 124 | + |
| 125 | + expect($databaseEntity->getProperty('Test Rollup')->getContent()["rollup_property_name"])->toBe("Tag"); |
| 126 | + expect($databaseEntity->getProperty('Test Rollup')->getContent()["relation_property_name"])->toBe("Test Relation"); |
| 127 | + expect($databaseEntity->getProperty('Test Rollup')->getContent()["function"])->toBe("unique"); |
| 128 | + |
117 | 129 | expect($databaseEntity->getProperty('Test Select')->getOptions())->toHaveCount(count($selectOptions)); |
118 | 130 | expect($databaseEntity->getProperty('Test Select')->getOptions()[0]->getName())->toEqual($selectOptions[0]['name']); |
119 | 131 | expect($databaseEntity->getProperty('Test Select')->getOptions()[0]->getColor())->toEqual($selectOptions[0]['color']); |
|
124 | 136 |
|
125 | 137 | expect($databaseEntity->getProperty('Test Number')->getRawResponse()['number']['format'])->toBe('dollar'); |
126 | 138 | }); |
| 139 | + |
| 140 | +it('should create a new database with default title property', function () { |
| 141 | + $this->httpRecorder->nameForNextRequest('with-emoji-icon'); |
| 142 | + |
| 143 | + $databaseEntity = Notion::databases() |
| 144 | + ->build() |
| 145 | + ->createInPage('0adbc2eb57e84569a700a70d537615be'); |
| 146 | + |
| 147 | + expect($databaseEntity->getProperties())->toHaveCount(1); |
| 148 | + expect($databaseEntity->getProperty('Name'))->toBeInstanceOf(Title::class); |
| 149 | +}); |
| 150 | + |
| 151 | + |
| 152 | +it('should create a new database with emoji icon', function () { |
| 153 | + $this->httpRecorder->nameForNextRequest('only-title-properties'); |
| 154 | + |
| 155 | + $databaseEntity = Notion::databases() |
| 156 | + ->build() |
| 157 | + ->iconEmoji('👍') |
| 158 | + ->createInPage('0adbc2eb57e84569a700a70d537615be'); |
| 159 | + |
| 160 | + expect($databaseEntity->getProperties())->toHaveCount(1); |
| 161 | + expect($databaseEntity->getProperty('Name'))->toBeInstanceOf(Title::class); |
| 162 | + expect($databaseEntity->getIcon())->toBe('👍'); |
| 163 | +}); |
0 commit comments