@@ -6,7 +6,8 @@ import { contentstackClient } from '../utility/ContentstackClient.js'
6
6
var client = { }
7
7
var stack = { }
8
8
9
- const taxonomy_uid = 'taxonomy_21'
9
+ const taxonomy_uid = ''
10
+ const term_uid = ''
10
11
const term = {
11
12
term : {
12
13
uid : 'term_test' ,
@@ -23,67 +24,114 @@ describe('Terms API Test', () => {
23
24
} )
24
25
25
26
it ( 'Create term' , async ( ) => {
26
- const response = await makeTerms ( ) . create ( [ { term } ] )
27
- console . log ( response )
28
- expect ( response . notice ) . to . be . equal ( 'Term created successfully.' )
29
- expect ( response . uid ) . to . be . equal ( term . term . uid )
27
+ try {
28
+ const response = await makeTerms ( taxonomy_uid ) . create ( term )
29
+ expect ( response . notice ) . to . be . equal ( 'Term created successfully.' )
30
+ expect ( response . uid ) . to . be . equal ( term . term . uid )
31
+ } catch ( err ) {
32
+ console . log ( err )
33
+ }
30
34
} )
31
35
32
36
it ( 'Query and get all terms' , async ( ) => {
33
- const response = await makeTerms ( ) . query ( ) . find ( )
34
- expect ( response . items ) . to . be . an ( 'array' )
35
- expect ( response . items [ 0 ] . uid ) . not . to . be . equal ( null )
36
- expect ( response . items [ 0 ] . name ) . not . to . be . equal ( null )
37
+ try {
38
+ const response = await makeTerms ( taxonomy_uid ) . query ( ) . find ( )
39
+ expect ( response . items ) . to . be . an ( 'array' )
40
+ expect ( response . items [ 0 ] . uid ) . not . to . be . equal ( null )
41
+ expect ( response . items [ 0 ] . name ) . not . to . be . equal ( null )
42
+ } catch ( err ) {
43
+ console . log ( err )
44
+ }
37
45
} )
38
46
39
47
it ( 'Fetch term from UID' , async ( ) => {
40
- const termsUid = 'fashion'
41
- const response = await makeTerms ( termsUid ) . fetch ( )
42
- expect ( response . uid ) . to . be . equal ( termsUid )
43
- expect ( response . name ) . not . to . be . equal ( null )
44
- expect ( response . created_by ) . not . to . be . equal ( null )
45
- expect ( response . updated_by ) . not . to . be . equal ( null )
48
+ try {
49
+ const response = await makeTerms ( taxonomy_uid , term_uid ) . fetch ( )
50
+ expect ( response . uid ) . to . be . equal ( term_uid )
51
+ expect ( response . name ) . not . to . be . equal ( null )
52
+ expect ( response . created_by ) . not . to . be . equal ( null )
53
+ expect ( response . updated_by ) . not . to . be . equal ( null )
54
+ } catch ( err ) {
55
+ console . log ( err )
56
+ }
46
57
} )
47
58
48
59
it ( 'Update term' , async ( ) => {
49
- const termsUid = 'fashion'
50
- const response = await makeTerms ( termsUid ) . fetch ( )
51
- . then ( ( term ) => {
52
- term . name = 'fashion'
53
- return term . update ( )
54
- } )
55
- expect ( response . notice ) . to . be . equal ( 'Term updated successfully.' )
56
- expect ( response . uid ) . to . be . equal ( termsUid )
57
- expect ( response . name ) . to . be . equal ( 'fashion' )
58
- expect ( response . created_by ) . not . to . be . equal ( null )
59
- expect ( response . updated_by ) . not . to . be . equal ( null )
60
+ try {
61
+ const response = await makeTerms ( taxonomy_uid , term_uid ) . fetch ( )
62
+ . then ( ( term ) => {
63
+ term . name = 'fashion'
64
+ return term . update ( )
65
+ } )
66
+ expect ( response . notice ) . to . be . equal ( 'Term updated successfully.' )
67
+ expect ( response . uid ) . to . be . equal ( term_uid )
68
+ expect ( response . name ) . to . be . equal ( 'fashion' )
69
+ expect ( response . created_by ) . not . to . be . equal ( null )
70
+ expect ( response . updated_by ) . not . to . be . equal ( null )
71
+ } catch ( err ) {
72
+ console . log ( err )
73
+ }
60
74
} )
61
75
62
76
it ( 'Delete term from UID' , async ( ) => {
63
- const termsUid = 'testing'
64
- const response = await makeTerms ( termsUid ) . delete ( )
65
- expect ( response . notice ) . to . be . equal ( '' )
77
+ try {
78
+ const response = await makeTerms ( term_uid ) . delete ( )
79
+ expect ( response . notice ) . to . be . equal ( '' )
80
+ } catch ( err ) {
81
+ console . log ( err )
82
+ }
66
83
} )
67
84
68
85
it ( 'Ancestors of the term given' , async ( ) => {
69
- const termsUid = 'term_3'
70
- const response = await makeTerms ( termsUid ) . ancestors ( )
71
- expect ( response . terms [ 0 ] . uid ) . not . to . be . equal ( null )
72
- expect ( response . terms [ 0 ] . name ) . not . to . be . equal ( null )
73
- expect ( response . terms [ 0 ] . created_by ) . not . to . be . equal ( null )
74
- expect ( response . terms [ 0 ] . updated_by ) . not . to . be . equal ( null )
86
+ try {
87
+ const response = await makeTerms ( taxonomy_uid , term_uid ) . ancestors ( )
88
+ expect ( response . terms [ 0 ] . uid ) . not . to . be . equal ( null )
89
+ expect ( response . terms [ 0 ] . name ) . not . to . be . equal ( null )
90
+ expect ( response . terms [ 0 ] . created_by ) . not . to . be . equal ( null )
91
+ expect ( response . terms [ 0 ] . updated_by ) . not . to . be . equal ( null )
92
+ } catch ( err ) {
93
+ console . log ( err )
94
+ }
75
95
} )
76
96
77
97
it ( 'Descendants of the term given' , async ( ) => {
78
- const termsUid = 'term_3'
79
- const response = await makeTerms ( termsUid ) . descendants ( )
80
- expect ( response . terms . uid ) . not . to . be . equal ( null )
81
- expect ( response . terms . name ) . not . to . be . equal ( null )
82
- expect ( response . terms . created_by ) . not . to . be . equal ( null )
83
- expect ( response . terms . updated_by ) . not . to . be . equal ( null )
98
+ try {
99
+ const response = await makeTerms ( taxonomy_uid , term_uid ) . descendants ( )
100
+ expect ( response . terms . uid ) . not . to . be . equal ( null )
101
+ expect ( response . terms . name ) . not . to . be . equal ( null )
102
+ expect ( response . terms . created_by ) . not . to . be . equal ( null )
103
+ expect ( response . terms . updated_by ) . not . to . be . equal ( null )
104
+ } catch ( err ) {
105
+ console . log ( err )
106
+ }
107
+ } )
108
+ it ( 'search term' , async ( ) => {
109
+ term_string = ''
110
+ try {
111
+ const response = await makeTerms ( taxonomy_uid ) . search ( term_string )
112
+ expect ( response . terms ) . to . be . an ( 'array' )
113
+ } catch ( err ) {
114
+ console . log ( err )
115
+ }
116
+ } )
117
+ it ( 'move term' , async ( ) => {
118
+ try {
119
+ const term = {
120
+ parent_uid : 'parent_uid' ,
121
+ order : 2
122
+ }
123
+ await makeTerms ( taxonomy_uid , term_uid ) . move ( { term } )
124
+ . then ( ( term ) => {
125
+ term . parent_uid = 'parent_uid'
126
+ console . log ( term . move ( ) )
127
+ return term . move ( )
128
+ } )
129
+ } catch ( err ) {
130
+ console . log ( err )
131
+ }
84
132
} )
85
133
} )
86
134
87
- function makeTerms ( uid = '' ) {
88
- return client . stack ( { api_key : stack . api_key } ) . taxonomy ( taxonomy_uid ) . terms ( uid )
135
+ function makeTerms ( taxonomy_uid , term_uid = null ) {
136
+ return client . stack ( { api_key : stack . api_key } ) . taxonomy ( taxonomy_uid ) . terms ( term_uid )
89
137
}
0 commit comments