1 | <?php |
||
2 | |||
3 | /** |
||
4 | * MIT License |
||
5 | * For full license information, please view the LICENSE file that was distributed with this source code. |
||
6 | */ |
||
7 | |||
8 | namespace SprykerTest\Zed\CommentDataImport\Communication\Plugin; |
||
9 | |||
10 | use Codeception\Test\Unit; |
||
11 | use Generated\Shared\Transfer\CustomerTransfer; |
||
12 | use Generated\Shared\Transfer\DataImporterConfigurationTransfer; |
||
13 | use Generated\Shared\Transfer\DataImporterReaderConfigurationTransfer; |
||
14 | use Generated\Shared\Transfer\DataImporterReportTransfer; |
||
15 | use Generated\Shared\Transfer\QuoteTransfer; |
||
16 | use Spryker\Zed\CommentDataImport\CommentDataImportConfig; |
||
17 | use Spryker\Zed\CommentDataImport\Communication\Plugin\CommentDataImportPlugin; |
||
18 | use Spryker\Zed\DataImport\Business\Exception\DataImportException; |
||
19 | |||
20 | /** |
||
21 | * Auto-generated group annotations |
||
22 | * |
||
23 | * @group SprykerTest |
||
24 | * @group Zed |
||
25 | * @group CommentDataImport |
||
26 | * @group Communication |
||
27 | * @group Plugin |
||
28 | * @group CommentDataImportPluginTest |
||
29 | * Add your own group annotations below this line |
||
30 | * @group Comment |
||
31 | */ |
||
32 | class CommentDataImportPluginTest extends Unit |
||
33 | { |
||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected const TEST_COMMENT_CUSTOMER_REFERENCE = 'test-comment-customer-reference'; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected const INCORRECT_COMMENT_CUSTOMER_REFERENCE = 'incorrect-comment-customer-reference'; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | protected const TEST_COMMENT_QUOTE_KEY = 'test-comment-owner-key'; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | protected const INCORRECT_COMMENT_QUOTE_KEY = 'incorrect-comment-owner-key'; |
||
53 | |||
54 | /** |
||
55 | * @var \SprykerTest\Zed\CommentDataImport\CommentDataImportCommunicationTester |
||
56 | */ |
||
57 | protected $tester; |
||
58 | |||
59 | /** |
||
60 | * @return void |
||
61 | */ |
||
62 | protected function setUp(): void |
||
63 | { |
||
64 | parent::setUp(); |
||
65 | |||
66 | $this->tester->ensureCommentTablesIsEmpty(); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return void |
||
71 | */ |
||
72 | public function testImportImportsData(): void |
||
73 | { |
||
74 | // Arrange |
||
75 | $this->tester->ensureCustomerWithReferenceDoesNotExist(static::TEST_COMMENT_CUSTOMER_REFERENCE); |
||
76 | $customerTransfer = $this->tester->createCustomer([ |
||
77 | CustomerTransfer::CUSTOMER_REFERENCE => static::TEST_COMMENT_CUSTOMER_REFERENCE, |
||
78 | ])->getCustomerTransfer(); |
||
79 | |||
80 | $this->tester->havePersistentQuote([ |
||
81 | QuoteTransfer::CUSTOMER => $customerTransfer, |
||
82 | QuoteTransfer::KEY => static::TEST_COMMENT_QUOTE_KEY, |
||
83 | ]); |
||
84 | |||
85 | $dataImporterReaderConfigurationTransfer = (new DataImporterReaderConfigurationTransfer()) |
||
86 | ->setFileName(codecept_data_dir() . 'import/comment.csv'); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
87 | |||
88 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||
89 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer); |
||
90 | |||
91 | // Act |
||
92 | $commentDataImportPlugin = new CommentDataImportPlugin(); |
||
93 | $dataImporterReportTransfer = $commentDataImportPlugin->import($dataImportConfigurationTransfer); |
||
94 | |||
95 | // Assert |
||
96 | $this->assertInstanceOf(DataImporterReportTransfer::class, $dataImporterReportTransfer); |
||
97 | $this->tester->assertCommentDatabaseTablesContainsData(); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @return void |
||
102 | */ |
||
103 | public function testImportThrowsExceptionWhenCustomerNotFound(): void |
||
104 | { |
||
105 | // Arrange |
||
106 | $dataImporterReaderConfigurationTransfer = (new DataImporterReaderConfigurationTransfer()) |
||
107 | ->setFileName(codecept_data_dir() . 'import/comment_customer_not_found.csv'); |
||
108 | |||
109 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||
110 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer) |
||
111 | ->setThrowException(true); |
||
112 | |||
113 | // Assert |
||
114 | $this->expectException(DataImportException::class); |
||
115 | $this->expectExceptionMessage(sprintf('Could not find customer by reference "%s"', static::INCORRECT_COMMENT_CUSTOMER_REFERENCE)); |
||
116 | |||
117 | // Act |
||
118 | $commentDataImportPlugin = new CommentDataImportPlugin(); |
||
119 | $commentDataImportPlugin->import($dataImportConfigurationTransfer); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @return void |
||
124 | */ |
||
125 | public function testImportThrowsExceptionWhenQuoteKeyNotFound(): void |
||
126 | { |
||
127 | // Arrange |
||
128 | $this->tester->ensureCustomerWithReferenceDoesNotExist(static::TEST_COMMENT_CUSTOMER_REFERENCE); |
||
129 | $this->tester->createCustomer([ |
||
130 | CustomerTransfer::CUSTOMER_REFERENCE => static::TEST_COMMENT_CUSTOMER_REFERENCE, |
||
131 | ])->getCustomerTransfer(); |
||
132 | |||
133 | $dataImporterReaderConfigurationTransfer = (new DataImporterReaderConfigurationTransfer()) |
||
134 | ->setFileName(codecept_data_dir() . 'import/comment_quote_not_found.csv'); |
||
135 | |||
136 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||
137 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer) |
||
138 | ->setThrowException(true); |
||
139 | |||
140 | // Assert |
||
141 | $this->expectException(DataImportException::class); |
||
142 | $this->expectExceptionMessage(sprintf('Could not find quote by key "%s"', static::INCORRECT_COMMENT_QUOTE_KEY)); |
||
143 | |||
144 | // Act |
||
145 | $commentDataImportPlugin = new CommentDataImportPlugin(); |
||
146 | $commentDataImportPlugin->import($dataImportConfigurationTransfer); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * @return void |
||
151 | */ |
||
152 | public function testImportThrowsExceptionWhenWrongOwnerType(): void |
||
153 | { |
||
154 | // Arrange |
||
155 | $this->tester->ensureCustomerWithReferenceDoesNotExist(static::TEST_COMMENT_CUSTOMER_REFERENCE); |
||
156 | $customerTransfer = $this->tester->createCustomer([ |
||
157 | CustomerTransfer::CUSTOMER_REFERENCE => static::TEST_COMMENT_CUSTOMER_REFERENCE, |
||
158 | ])->getCustomerTransfer(); |
||
159 | |||
160 | $this->tester->havePersistentQuote([ |
||
161 | QuoteTransfer::CUSTOMER => $customerTransfer, |
||
162 | QuoteTransfer::KEY => static::TEST_COMMENT_QUOTE_KEY, |
||
163 | ]); |
||
164 | |||
165 | $dataImporterReaderConfigurationTransfer = (new DataImporterReaderConfigurationTransfer()) |
||
166 | ->setFileName(codecept_data_dir() . 'import/comment_wrong_owner_type.csv'); |
||
167 | |||
168 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||
169 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer) |
||
170 | ->setThrowException(true); |
||
171 | |||
172 | // Assert |
||
173 | $this->expectException(DataImportException::class); |
||
174 | $this->expectExceptionMessage(sprintf('Could not find owner id by owner key "%s"', static::TEST_COMMENT_QUOTE_KEY)); |
||
175 | |||
176 | // Act |
||
177 | $commentDataImportPlugin = new CommentDataImportPlugin(); |
||
178 | $commentDataImportPlugin->import($dataImportConfigurationTransfer); |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @return void |
||
183 | */ |
||
184 | public function testImportThrowsExceptionWhenEmptyCommentMessage(): void |
||
185 | { |
||
186 | // Arrange |
||
187 | $this->tester->ensureCustomerWithReferenceDoesNotExist(static::TEST_COMMENT_CUSTOMER_REFERENCE); |
||
188 | $customerTransfer = $this->tester->createCustomer([ |
||
189 | CustomerTransfer::CUSTOMER_REFERENCE => static::TEST_COMMENT_CUSTOMER_REFERENCE, |
||
190 | ])->getCustomerTransfer(); |
||
191 | |||
192 | $this->tester->havePersistentQuote([ |
||
193 | QuoteTransfer::CUSTOMER => $customerTransfer, |
||
194 | QuoteTransfer::KEY => static::TEST_COMMENT_QUOTE_KEY, |
||
195 | ]); |
||
196 | |||
197 | $dataImporterReaderConfigurationTransfer = (new DataImporterReaderConfigurationTransfer()) |
||
198 | ->setFileName(codecept_data_dir() . 'import/comment_empty_message.csv'); |
||
199 | |||
200 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||
201 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer) |
||
202 | ->setThrowException(true); |
||
203 | |||
204 | // Assert |
||
205 | $this->expectException(DataImportException::class); |
||
206 | $this->expectExceptionMessage(sprintf('The comment message should not be empty.')); |
||
207 | |||
208 | // Act |
||
209 | $commentDataImportPlugin = new CommentDataImportPlugin(); |
||
210 | $commentDataImportPlugin->import($dataImportConfigurationTransfer); |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * @return void |
||
215 | */ |
||
216 | public function testGetImportTypeReturnsTypeOfImporter(): void |
||
217 | { |
||
218 | // Act |
||
219 | $commentDataImportPlugin = new CommentDataImportPlugin(); |
||
220 | |||
221 | // Assert |
||
222 | $this->assertSame(CommentDataImportConfig::IMPORT_TYPE_COMMENT, $commentDataImportPlugin->getImportType()); |
||
223 | } |
||
224 | } |
||
225 |