@@ -194,6 +194,68 @@ describe('Process WordPress REST API JSON', function () {
194194 assert . equal ( data . tags [ 5 ] . data . name , '#wp' ) ;
195195 } ) ;
196196
197+ it ( 'Can include custom taxonomy terms as tags' , async function ( ) {
198+ const fixture = structuredClone ( singlePostFixture ) ;
199+ fixture . _embedded [ 'wp:term' ] . push ( [
200+ { id : 350 , link : 'https://mysite.com/country/czech-republic' , name : 'Czech Republic' , slug : 'czech-republic' , taxonomy : 'country' } ,
201+ { id : 12 , link : 'https://mysite.com/country/romania' , name : 'Romania' , slug : 'romania' , taxonomy : 'country' }
202+ ] ) ;
203+ fixture . _embedded [ 'wp:term' ] . push ( [
204+ { id : 500 , link : 'https://mysite.com/city/prague' , name : 'Prague' , slug : 'prague' , taxonomy : 'city' }
205+ ] ) ;
206+
207+ const users = [ ] ;
208+ const options = { tags : true , addTag : null , featureImage : 'featuredmedia' , url : 'https://mysite.com' , customTaxonomies : [ 'country' ] } ;
209+ const post = await processor . processPost ( fixture , users , options ) ;
210+
211+ const tagSlugs = post . data . tags . map ( t => t . data . slug ) ;
212+ assert . ok ( tagSlugs . includes ( 'czech-republic' ) , 'should include country term czech-republic' ) ;
213+ assert . ok ( tagSlugs . includes ( 'romania' ) , 'should include country term romania' ) ;
214+ assert . ok ( ! tagSlugs . includes ( 'prague' ) , 'should not include city term when not in customTaxonomies' ) ;
215+ } ) ;
216+
217+ it ( 'Does not include custom taxonomy terms when customTaxonomies is not set' , async function ( ) {
218+ const fixture = structuredClone ( singlePostFixture ) ;
219+ fixture . _embedded [ 'wp:term' ] . push ( [
220+ { id : 350 , link : 'https://mysite.com/country/czech-republic' , name : 'Czech Republic' , slug : 'czech-republic' , taxonomy : 'country' }
221+ ] ) ;
222+
223+ const users = [ ] ;
224+ const options = { tags : true , addTag : null , featureImage : 'featuredmedia' , url : 'https://mysite.com' } ;
225+ const post = await processor . processPost ( fixture , users , options ) ;
226+
227+ const tagSlugs = post . data . tags . map ( t => t . data . slug ) ;
228+ assert . ok ( ! tagSlugs . includes ( 'czech-republic' ) , 'should not include country term when customTaxonomies is not set' ) ;
229+ } ) ;
230+
231+ it ( 'processTerms handles custom taxonomies directly' , function ( ) {
232+ const wpTerms = [
233+ [ { id : 1 , link : 'https://mysite.com/category/news' , name : 'News' , slug : 'news' , taxonomy : 'category' } ] ,
234+ [ { id : 2 , link : 'https://mysite.com/tag/tech' , name : 'Tech' , slug : 'tech' , taxonomy : 'post_tag' } ] ,
235+ [ { id : 350 , link : 'https://mysite.com/country/romania' , name : 'Romania' , slug : 'romania' , taxonomy : 'country' } ]
236+ ] ;
237+
238+ const result = processor . processTerms ( wpTerms , true , [ 'country' ] ) ;
239+ assert . equal ( result . length , 3 ) ;
240+ assert . equal ( result [ 0 ] . data . slug , 'news' ) ;
241+ assert . equal ( result [ 1 ] . data . slug , 'tech' ) ;
242+ assert . equal ( result [ 2 ] . data . slug , 'romania' ) ;
243+ } ) ;
244+
245+ it ( 'processTerms handles multiple custom taxonomies' , function ( ) {
246+ const wpTerms = [
247+ [ { id : 1 , link : 'https://mysite.com/category/news' , name : 'News' , slug : 'news' , taxonomy : 'category' } ] ,
248+ [ { id : 350 , link : 'https://mysite.com/country/romania' , name : 'Romania' , slug : 'romania' , taxonomy : 'country' } ] ,
249+ [ { id : 500 , link : 'https://mysite.com/city/bucharest' , name : 'Bucharest' , slug : 'bucharest' , taxonomy : 'city' } ]
250+ ] ;
251+
252+ const result = processor . processTerms ( wpTerms , false , [ 'country' , 'city' ] ) ;
253+ assert . equal ( result . length , 3 ) ;
254+ assert . equal ( result [ 0 ] . data . slug , 'news' ) ;
255+ assert . equal ( result [ 1 ] . data . slug , 'romania' ) ;
256+ assert . equal ( result [ 2 ] . data . slug , 'bucharest' ) ;
257+ } ) ;
258+
197259 it ( 'Can remove first image in post if same as feature image' , async function ( ) {
198260 const users = [ ] ;
199261 const options = { tags : true , addTag : null , featureImage : 'featuredmedia' , url : 'https://mysite.com' , cpt : 'mycpt' } ;
0 commit comments