1
- const { TABLE_HEADERS } = require ( '../lib/constant' ) ;
1
+ const { LIST_TABLE_HEADERS , USER_TABLE_HEADERS } = require ( '../lib/constant' ) ;
2
2
const {
3
3
convertToDate,
4
4
getListTable,
5
5
mapToVisibilityString,
6
6
mapToVisiblityCode,
7
7
tokenGuard,
8
+ mapAccountPremium,
9
+ mapAccountVisibility,
10
+ getUserData,
8
11
} = require ( '../lib/util' ) ;
9
- const { getXml } = require ( './helper/test-helper' ) ;
12
+ const { getPasteListXml , getUserXml } = require ( './helper/test-helper' ) ;
10
13
11
14
describe ( 'mapToVisibilityString' , ( ) => {
12
15
const fixtures = [
@@ -86,7 +89,7 @@ describe('getListTable', () => {
86
89
const pasteExpiryDate = '0' ;
87
90
const pasteFormat = 'text' ;
88
91
89
- const xml = getXml (
92
+ const xml = getPasteListXml (
90
93
pasteKey ,
91
94
pasteName ,
92
95
pasteVisibility ,
@@ -95,7 +98,7 @@ describe('getListTable', () => {
95
98
) ;
96
99
97
100
expect ( getListTable ( xml ) ) . toEqual ( [
98
- [ ...TABLE_HEADERS ] ,
101
+ [ ...LIST_TABLE_HEADERS ] ,
99
102
[ pasteKey , pasteName , 'unlisted' , 'Never' , pasteFormat ] ,
100
103
] ) ;
101
104
} ) ;
@@ -113,14 +116,14 @@ describe('getListTable', () => {
113
116
const pasteExpiryDate2 = '1640992515' ;
114
117
const pasteFormat2 = 'javascript' ;
115
118
116
- const xml = `${ getXml (
119
+ const xml = `${ getPasteListXml (
117
120
pasteKey ,
118
121
pasteName ,
119
122
pasteVisibility ,
120
123
pasteExpiryDate ,
121
124
pasteFormat
122
125
) }
123
- ${ getXml (
126
+ ${ getPasteListXml (
124
127
pasteKey2 ,
125
128
pasteName2 ,
126
129
pasteVisibility2 ,
@@ -129,9 +132,53 @@ describe('getListTable', () => {
129
132
) } `;
130
133
131
134
expect ( getListTable ( xml ) ) . toEqual ( [
132
- [ ...TABLE_HEADERS ] ,
135
+ [ ...LIST_TABLE_HEADERS ] ,
133
136
[ pasteKey , pasteName , 'unlisted' , 'Never' , pasteFormat ] ,
134
137
[ pasteKey2 , pasteName2 , 'public' , '01.01.2022 00:15' , pasteFormat2 ] ,
135
138
] ) ;
136
139
} ) ;
137
140
} ) ;
141
+
142
+ describe ( 'mapAccountPremium' , ( ) => {
143
+ it ( 'should return free for 0' , ( ) => {
144
+ expect ( mapAccountPremium ( 0 ) ) . toBe ( 'free' ) ;
145
+ } ) ;
146
+
147
+ it ( 'should return premium for 1' , ( ) => {
148
+ expect ( mapAccountPremium ( 1 ) ) . toBe ( 'premium' ) ;
149
+ } ) ;
150
+ } ) ;
151
+
152
+ describe ( 'mapAccountVisibility' , ( ) => {
153
+ it ( 'should return public for 0' , ( ) => {
154
+ expect ( mapAccountVisibility ( 0 ) ) . toBe ( 'public' ) ;
155
+ } ) ;
156
+
157
+ it ( 'should return unlisted for 1' , ( ) => {
158
+ expect ( mapAccountVisibility ( 1 ) ) . toBe ( 'unlisted' ) ;
159
+ } ) ;
160
+
161
+ it ( 'should return private for 2' , ( ) => {
162
+ expect ( mapAccountVisibility ( 2 ) ) . toBe ( 'private' ) ;
163
+ } ) ;
164
+
165
+ it ( 'should return error for something else' , ( ) => {
166
+ expect ( mapAccountVisibility ( 3 ) ) . toBe ( 'error, could not get from api' ) ;
167
+ } ) ;
168
+ } ) ;
169
+
170
+ describe ( 'getUserData' , ( ) => {
171
+ it ( 'should return table with mapped data' , ( ) => {
172
+ const userName = 'test user' ;
173
+ const privacy = '0' ;
174
+ const email = '[email protected] ' ;
175
+ const premium = '1' ;
176
+
177
+ const xml = getUserXml ( userName , privacy , email , premium ) ;
178
+
179
+ expect ( getUserData ( xml ) ) . toEqual ( [
180
+ [ ...USER_TABLE_HEADERS ] ,
181
+ [ userName , 'public' , email , 'premium' ] ,
182
+ ] ) ;
183
+ } ) ;
184
+ } ) ;
0 commit comments