UNPKG

2.07 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
12describe( 'wpcom.site.post.like', function() {
13 // Global instances
14 var wpcom = util.wpcom();
15 var site = wpcom.site( util.site() );
16 var testing_post;
17
18 // Create a testing_post before to start the tests
19 before( done => {
20 site.addPost( fixture.post )
21 .then( data => {
22 testing_post = site.post( data.ID );
23 done();
24 } )
25 .catch( done );
26 } );
27
28 after( done => {
29 // delete testing_post post
30 testing_post.delete()
31 .then( () => done() )
32 .catch( done );
33 } );
34
35 describe( 'wpcom.site.post.like.add', function() {
36 it( 'should add a post like', done => {
37 testing_post.like().add()
38 .then( data => {
39 assert.ok( data );
40 assert.ok( data.success );
41 assert.ok( data.i_like );
42 assert.equal( 1, data.like_count );
43
44 done();
45 } )
46 .catch( done );
47 } );
48 } );
49
50 describe( 'wpcom.site.post.like.mine', function() {
51 it( 'should get the post like status of mine', done => {
52 testing_post.like().mine()
53 .then( data => {
54 assert.ok( data );
55 assert.equal( 1, data.like_count );
56 assert.ok( data.i_like );
57
58 done();
59 } )
60 .catch( done );
61 } );
62 } );
63
64 describe( 'wpcom.site.post.likesList', function() {
65 it( 'should get post likes list', done => {
66 testing_post.likesList()
67 .then( data => {
68 assert.ok( data );
69
70 assert.equal( 'number', typeof data.found );
71 assert.equal( 'boolean', typeof data.i_like );
72 assert.equal( 'object', typeof data.likes );
73 assert.ok( data.likes instanceof Array );
74
75 done();
76 } )
77 .catch( done );
78 } );
79 } );
80
81 describe( 'wpcom.site.post.like.delete', function() {
82 it( 'should remove your like from the post', done => {
83 testing_post.like().del()
84 .then( data => {
85 assert.ok( data );
86 assert.ok( data.success );
87 assert.equal( 0, data.like_count );
88 assert.ok( ! ( data.i_like ) );
89
90 done();
91 } )
92 .catch( done );
93 } );
94 } );
95} );