UNPKG

3.4 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 * wpcom.site.post.subscriber
14 */
15describe( 'wpcom.site.post.subscriber', function() {
16 // Global instances
17 var wpcom = util.wpcom();
18 var site = wpcom.site( fixture.site );
19 var testing_post;
20
21 before( function( done ) {
22 site.addPost( fixture.post, function( err, data ) {
23 if ( err ) throw err;
24
25 testing_post = site.post( data.ID );
26 done();
27 } );
28 } );
29
30 after( function( done ) {
31 // delete testing_post post
32 testing_post.delete( function( err ) {
33 if ( err ) throw err;
34
35 done();
36 } );
37 } );
38
39 describe( 'wpcom.site.post.subscribersList', function() {
40 it( 'should get subscribers post list', function( done ) {
41 testing_post.subscribersList( function( err, data ) {
42 if ( err ) throw err;
43
44 assert.equal( 'number', typeof data.found );
45 assert.equal( 0, data.found );
46 assert.equal( 'object', typeof data.subscriptions );
47 assert.ok( data.subscriptions instanceof Array );
48 done();
49 } );
50 } );
51 } );
52
53 describe( 'wpcom.site.post.subscriber.mine', function() {
54 it( 'should get subscribe status `FALSE` for current user', function( done ) {
55 testing_post
56 .subscriber()
57 .mine( function( err, data ) {
58 if ( err ) throw err;
59
60 assert.ok( data );
61 assert.equal( false, data.i_subscribe );
62
63 done();
64 } );
65 } );
66 } );
67
68 describe( 'wpcom.site.post.subscriber.add', function() {
69 it( 'should subscribe current user to the post', function( done ) {
70 testing_post
71 .subscriber()
72 .add( function( err, data ) {
73 if ( err ) throw err;
74
75 assert.ok( data );
76 assert.equal( true, data.success );
77 assert.equal( true, data.i_subscribe );
78 done();
79 } );
80 } );
81 } );
82
83 describe( 'wpcom.site.post.subscriber.mine', function() {
84 it( 'should get subscribe status `TRUE` for current user', function( done ) {
85 testing_post
86 .subscriber()
87 .mine( function( err, data ) {
88 if ( err ) throw err;
89
90 assert.ok( data );
91 assert.equal( true, data.i_subscribe );
92 done();
93 } );
94 } );
95 } );
96
97 describe( 'wpcom.site.post.subscribersList', function() {
98 it( 'should get subscribers post list = 1', function( done ) {
99 testing_post.subscribersList( function( err, data ) {
100 if ( err ) throw err;
101
102 assert.equal( 'number', typeof data.found );
103 assert.equal( 1, data.found );
104 assert.equal( 'object', typeof data.subscriptions );
105 assert.ok( data.subscriptions instanceof Array );
106 done();
107 } );
108 } );
109 } );
110
111 describe( 'wpcom.site.post.subscriber.delete', function() {
112 it( 'should unsubscribe current user from the post', function( done ) {
113 testing_post
114 .subscriber()
115 .delete( function( err, data ) {
116 if ( err ) throw err;
117
118 assert.ok( data );
119 assert.equal( true, data.success );
120 assert.equal( false, data.i_subscribe );
121 done();
122 } );
123 } );
124 } );
125
126 describe( 'wpcom.site.post.subscribersList', function() {
127 it( 'should get subscribers post list = 0', function( done ) {
128 testing_post.subscribersList( function( err, data ) {
129 if ( err ) throw err;
130
131 assert.equal( 'number', typeof data.found );
132 assert.equal( 0, data.found );
133 assert.equal( 'object', typeof data.subscriptions );
134 assert.ok( data.subscriptions instanceof Array );
135 done();
136 } );
137 } );
138 } );
139} );