1 |
|
2 |
|
3 |
|
4 | var util = require( './util' );
|
5 | var assert = require( 'assert' );
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | describe( 'wpcom.site.taxonomy.term', () => {
|
11 |
|
12 | const wpcom = util.wpcom();
|
13 | const site = wpcom.site( util.site() );
|
14 | const taxonomy = site.taxonomy( 'category' );
|
15 | const testTermAttributes = { name: 'Chicken and Ribs', description: 'noms' };
|
16 | let testTerm;
|
17 | let testTermTwo;
|
18 |
|
19 |
|
20 | before( done => {
|
21 | taxonomy.term().add( testTermAttributes )
|
22 | .then( term => {
|
23 | testTerm = term;
|
24 | done();
|
25 | } )
|
26 | .catch( done );
|
27 | } );
|
28 |
|
29 | after( done => {
|
30 |
|
31 | taxonomy.term( testTerm.slug ).delete()
|
32 | .then( () => done() )
|
33 | .catch( done );
|
34 | } );
|
35 |
|
36 | describe( 'wpcom.site.taxonomy.term.get', () => {
|
37 | it( 'should return term details', done => {
|
38 | taxonomy.term( testTerm.slug ).get()
|
39 | .then( data => {
|
40 | assert.ok( data );
|
41 | assert.ok( 'string', typeof data.name );
|
42 | assert.ok( 'string', typeof data.slug );
|
43 | assert.ok( 'string', typeof data.description );
|
44 | assert.ok( 'number', typeof data.post_count );
|
45 | assert.ok( 'number', typeof data.parent );
|
46 | assert.ok( 'number', typeof data.ID );
|
47 | assert.equal( testTerm.ID, data.ID );
|
48 | assert.equal( testTerm.name, data.name );
|
49 | done();
|
50 | } )
|
51 | .catch( done );
|
52 | } );
|
53 |
|
54 | it( 'should not return an error for unknown_taxonomy', done => {
|
55 | taxonomy.term( 'i-ate-all-the-chicken-and-ribs' ).get()
|
56 | .catch( data => {
|
57 | assert.ok( data );
|
58 | assert.equal( data.error, 'unknown_taxonomy' );
|
59 | done();
|
60 | } );
|
61 | } );
|
62 | } );
|
63 |
|
64 | describe( 'wpcom.site.taxonomy.term.add', () => {
|
65 | it( 'should create a new term', done => {
|
66 | taxonomy.term().add( { name: 'chunky bacon', parent: testTerm.ID, description: 'I LOVE BACON MOAR' } )
|
67 | .then( data => {
|
68 | testTermTwo = data;
|
69 | assert.ok( data );
|
70 | assert.equal( data.name, 'chunky bacon' );
|
71 | assert.equal( data.parent, testTerm.ID );
|
72 | assert.equal( data.description, 'I LOVE BACON MOAR' );
|
73 | done();
|
74 | } )
|
75 | .catch( done );
|
76 | } );
|
77 | } );
|
78 |
|
79 | describe( 'wpcom.site.taxonomy.term.update', () => {
|
80 | it( 'should update the term', done => {
|
81 | taxonomy.term( testTermTwo.slug ).update( { parent: 0, description: 'I LOVE RIBS AND BACON' } )
|
82 | .then( data => {
|
83 | assert.ok( data );
|
84 | assert.equal( data.slug, testTermTwo.slug );
|
85 | assert.equal( data.description, 'I LOVE RIBS AND BACON' );
|
86 | assert.equal( data.parent, 0 );
|
87 | done();
|
88 | } )
|
89 | .catch( done );
|
90 | } );
|
91 | } );
|
92 |
|
93 | describe( 'wpcom.site.taxonomy.term.delete', () => {
|
94 | it( 'should update the term', done => {
|
95 | taxonomy.term( testTermTwo.slug ).delete()
|
96 | .then( data => {
|
97 | assert.ok( data );
|
98 | done();
|
99 | } )
|
100 | .catch( done );
|
101 | } );
|
102 | } );
|
103 | } );
|