UNPKG

4.5 kBJavaScriptView Raw
1/**
2 * Module dependencies
3 */
4var util = require( './util' );
5var assert = require( 'assert' );
6
7/**
8 * Testing data
9 */
10var fixture = require( './fixture' );
11
12/**
13 * site.post.comment
14 */
15describe( 'wpcom.site.post.comment', function() {
16 // Global instances
17 var wpcom = util.wpcom();
18 var site = wpcom.site( util.site() );
19 var testing_post;
20 var testing_comment;
21
22 before( done => {
23 site.addPost( fixture.post )
24 .then( data => {
25 testing_post = site.post( data.ID );
26
27 // Add comment to post
28 return site.post( data.ID ).comment().add( fixture.post_comment );
29 } )
30 .then( data_comment => {
31 testing_comment = testing_post.comment( data_comment.ID );
32 done();
33 } )
34 .catch( done );
35 } );
36
37 after( function( done ) {
38 // delete testing_post post
39 testing_post.delete( function( err ) {
40 if ( err ) throw err;
41
42 done();
43 } );
44 } );
45
46 describe( 'wpcom.site.post.comment.add', function() {
47 it( 'should add a post comment', function( done ) {
48 testing_comment.add( fixture.post_comment + '-added', function( err, data ) {
49 if ( err ) throw err;
50
51 assert.equal( 'number', typeof data.ID );
52 assert.equal( 'object', typeof data.post );
53 assert.ok( data.post instanceof Object );
54
55 done();
56 } );
57 } );
58 } );
59
60 describe( 'wpcom.site.post.comment.update', function() {
61 it( 'should update a post comment', function( done ) {
62 testing_comment.update( fixture.post_comment + '-updated', function( err, data ) {
63 if ( err ) throw err;
64
65 assert.equal( 'number', typeof data.ID );
66 assert.equal( 'object', typeof data.post );
67 assert.ok( data.post instanceof Object );
68 assert.equal( testing_comment._cid, data.ID );
69
70 done();
71 } );
72 } );
73 } );
74
75 describe( 'wpcom.site.post.comment.reply', function() {
76 it( 'should add a reply to a post comment', function( done ) {
77 testing_comment.reply( fixture.post_comment + '-replied', function( err, data ) {
78 if ( err ) throw err;
79
80 assert.equal( 'number', typeof data.ID );
81 assert.equal( 'object', typeof data.post );
82 assert.ok( data.post instanceof Object );
83 assert.equal( testing_comment._cid, data.parent.ID );
84
85 done();
86 } );
87 } );
88 } );
89
90 describe( 'wpcom.site.post.comment.like.add', function() {
91 it( 'should add a comment like', function( done ) {
92 testing_comment
93 .like()
94 .add( function( err, data ) {
95 if ( err ) throw err;
96
97 assert.ok( data );
98 assert.equal( 1, data.like_count );
99 assert.ok( data.i_like );
100
101 done();
102 } );
103 } );
104 } );
105
106 describe( 'wpcom.site.post.comment.like.mine', function() {
107 it( 'should get the comment like status of mine', function( done ) {
108 testing_comment
109 .like()
110 .mine( function( err, data ) {
111 if ( err ) throw err;
112
113 assert.ok( data );
114 assert.equal( 1, data.like_count );
115 assert.ok( data.i_like );
116
117 done();
118 } );
119 } );
120 } );
121
122 describe( 'wpcom.site.post.comment.likesList', function() {
123 it( 'should get comment likes list', function( done ) {
124 testing_comment.likesList( function( err, data ) {
125 if ( err ) throw err;
126
127 assert.ok( data );
128 assert.equal( 'number', typeof data.found );
129 assert.equal( 'boolean', typeof data.i_like );
130 assert.equal( 'object', typeof data.likes );
131 assert.ok( data.likes instanceof Array );
132
133 done();
134 } );
135 } );
136 } );
137
138 describe( 'wpcom.site.post.comment.like.delete', function() {
139 it( 'should remove your like from the comment', function( done ) {
140 testing_comment
141 .like()
142 .del( function( err, data ) {
143 if ( err ) throw err;
144
145 assert.ok( data );
146 assert.ok( data.success );
147 assert.equal( 0, data.like_count );
148 assert.ok( ! ( data.i_like ) );
149
150 done();
151 } );
152 } );
153 } );
154
155 describe( 'wpcom.site.post.comments', function() {
156 it( 'should get the post comments list', function( done ) {
157 testing_post
158 .comments( function( err, data ) {
159 if ( err ) throw err;
160
161 assert.equal( 'number', typeof data.found );
162 assert.equal( 'object', typeof data.comments );
163 assert.ok( data.comments instanceof Array );
164
165 done();
166 } );
167 } );
168 } );
169
170 describe( 'wpcom.site.post.comment.delete', function() {
171 it( 'should delete a comment', function( done ) {
172 testing_comment.del( function( err, data ) {
173 if ( err ) throw err;
174
175 assert.equal( 'number', typeof data.ID );
176 assert.equal( 'object', typeof data.post );
177 assert.ok( data.post instanceof Object );
178 assert.equal( testing_comment._cid, data.ID );
179
180 done();
181 } );
182 } );
183 } );
184} );