Pārlūkot izejas kodu

:white_check_mark: Finished editing membership /<profile_id> test

brian_tests
tomit4 2 gadus atpakaļ
vecāks
revīzija
6e6054afcd

+ 0
- 3
backend/lib/routes/membership/active.js Parādīt failu

123
                           'reveal',
123
                           'reveal',
124
                       )
124
                       )
125
                     : undefined
125
                     : undefined
126
-            console.log('revealTags :=>', revealTags)
127
 
126
 
128
             /** If the revealTags exist, the completedProfile's hidden info is
127
             /** If the revealTags exist, the completedProfile's hidden info is
129
              * removed and replaced with the completedProfile's user information
128
              * removed and replaced with the completedProfile's user information
134
                       completedProfiles.map(p => p.user_id),
133
                       completedProfiles.map(p => p.user_id),
135
                   )
134
                   )
136
                 : undefined
135
                 : undefined
137
-            console.log('user :=>', user)
138
 
136
 
139
             // TODO: Refactor this. Is it safe to always use completedProfiles[0]?
137
             // TODO: Refactor this. Is it safe to always use completedProfiles[0]?
140
             if (revealTags && user) {
138
             if (revealTags && user) {
141
                 revealTags.forEach(t => {
139
                 revealTags.forEach(t => {
142
-                    console.log('t :=>', t)
143
                     if (!t.tag.tag_description) return
140
                     if (!t.tag.tag_description) return
144
                     completedProfiles[0][t.tag.tag_description] =
141
                     completedProfiles[0][t.tag.tag_description] =
145
                         user[t.tag.tag_description]
142
                         user[t.tag.tag_description]

+ 7
- 13
backend/lib/services/profile/index.js Parādīt failu

372
      * @param {object}
372
      * @param {object}
373
      */
373
      */
374
     async getTagsFor(profileId, groupingId, category) {
374
     async getTagsFor(profileId, groupingId, category) {
375
-        console.log('profileId :=>', profileId) // [ 1, 2 ]
376
-        console.log('groupingId :=>', groupingId) // [ 1 ]
377
-        console.log('category :=>', category) // 'reveal'
378
         const { TagAssociation } = this.server.models()
375
         const { TagAssociation } = this.server.models()
379
         await this._setTagLookup()
376
         await this._setTagLookup()
380
-        console.log('this.tagLookup :=>', this.tagLookup) // {}
381
         let associations = []
377
         let associations = []
382
         if (!profileId.length || !groupingId.length) {
378
         if (!profileId.length || !groupingId.length) {
383
             return associations
379
             return associations
388
                       .where('grouping_id', groupingId)
384
                       .where('grouping_id', groupingId)
389
                       .andWhere('profile_id', profileId)
385
                       .andWhere('profile_id', profileId)
390
                 : await TagAssociation.query().andWhere('profile_id', profileId)
386
                 : await TagAssociation.query().andWhere('profile_id', profileId)
391
-            // filter doesn't fire in tests (incorrect format?)
392
-            return associations.map(assoc => ({
393
-                ...assoc,
394
-                tag: this.tagLookup[assoc.tag_id]
395
-                    ? {}
396
-                    : this.tagLookup[assoc.tag_id],
397
-            }))
398
-            /*
387
+            return associations
388
+                .map(assoc => ({
389
+                    ...assoc,
390
+                    tag: !this.tagLookup[assoc.tag_id]
391
+                        ? {}
392
+                        : this.tagLookup[assoc.tag_id],
393
+                }))
399
                 .filter(tagWithAssoc => {
394
                 .filter(tagWithAssoc => {
400
                     return category
395
                     return category
401
                         ? tagWithAssoc.tag.tag_category == category
396
                         ? tagWithAssoc.tag.tag_category == category
402
                         : true
397
                         : true
403
                 })
398
                 })
404
-            */
405
         }
399
         }
406
     }
400
     }
407
 
401
 

+ 15
- 16
backend/tests/membership.spec.js Parādīt failu

16
 const Tag = require('../lib/models/tag')
16
 const Tag = require('../lib/models/tag')
17
 const TagAssociation = require('../lib/models/tag-association')
17
 const TagAssociation = require('../lib/models/tag-association')
18
 const User = require('../lib/models/user')
18
 const User = require('../lib/models/user')
19
-const ZipCode = require('../lib/models/zip-code')
20
 const Aspect = require('../lib/models/aspect')
19
 const Aspect = require('../lib/models/aspect')
21
 const AspectLabel = require('../lib/models/aspect_label')
20
 const AspectLabel = require('../lib/models/aspect_label')
22
 
21
 
93
             grouping_id: 1,
92
             grouping_id: 1,
94
             tag_id: 7,
93
             tag_id: 7,
95
             is_deleted: 0,
94
             is_deleted: 0,
96
-            tag: {
97
-                tag_category: 'reveal',
98
-            },
99
         },
95
         },
100
         {
96
         {
101
             tag_association_id: 2,
97
             tag_association_id: 2,
102
             profile_id: 1,
98
             profile_id: 1,
103
             grouping_id: 1,
99
             grouping_id: 1,
104
-            tag_id: 7,
100
+            tag_id: 8,
105
             is_deleted: 0,
101
             is_deleted: 0,
106
-            tag: {
107
-                tag_category: 'reveal',
108
-            },
109
         },
102
         },
110
     ],
103
     ],
111
-    tags: [],
104
+    tags: [
105
+        {
106
+            tag_id: 7,
107
+            tag_category: 'reveal',
108
+            tag_description: 'user_name',
109
+            is_active: 1,
110
+        },
111
+        {
112
+            tag_id: 8,
113
+            tag_category: 'reveal',
114
+            tag_description: 'user_email',
115
+            is_active: 1,
116
+        },
117
+    ],
112
     labels: [
118
     labels: [
113
         { aspect_id: 1, a: 100, b: 100 },
119
         { aspect_id: 1, a: 100, b: 100 },
114
         { aspect_id: 2, a: 100, b: 200 },
120
         { aspect_id: 2, a: 100, b: 200 },
164
         User,
170
         User,
165
     })
171
     })
166
 
172
 
167
-    // server.registerService(ProfileService)
168
-    // server.registerService(MembershipService)
169
-    // server.registerService(UserService)
170
     /**
173
     /**
171
      * Register Routes and Services as usual
174
      * Register Routes and Services as usual
172
      */
175
      */
239
     const { payload } = await server.inject(pathToTest)
242
     const { payload } = await server.inject(pathToTest)
240
     const res = JSON.parse(payload)
243
     const res = JSON.parse(payload)
241
 
244
 
242
-    t.log('res :=>', res)
243
     t.deepEqual(res.ok, true)
245
     t.deepEqual(res.ok, true)
244
     t.deepEqual(res.data.length, 1)
246
     t.deepEqual(res.data.length, 1)
245
-
246
-    /*
247
     t.deepEqual(res.data[0].grouping_id, mockReturn.groupings[0].grouping_id)
247
     t.deepEqual(res.data[0].grouping_id, mockReturn.groupings[0].grouping_id)
248
     t.deepEqual(
248
     t.deepEqual(
249
         res.data[0].profile.user_name,
249
         res.data[0].profile.user_name,
250
         mockReturn.groupings[0].profile.user_name,
250
         mockReturn.groupings[0].profile.user_name,
251
     )
251
     )
252
-    */
253
 })
252
 })

Notiek ielāde…
Atcelt
Saglabāt