How to use extractData method in Jest

Best JavaScript code snippet using jest

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

board.js

Source: board.js Github

copy
1(function () {
2    'use strict';
3
4    var services = angular.module('lavagna.services');
5
6    var extractData = function (data) {
7        return data.data;
8    };
9
10    services.factory('Board', function ($http) {
11        return {
12            findByShortName: function (shortName) {
13                return $http.get('api/board/' + shortName).then(extractData);
14            },
15
16            suggestShortName: function (name) {
17                return $http.get('api/suggest-board-short-name', {params: {name: name}}).then(extractData);
18            },
19
20            checkShortName: function (name) {
21                return $http.get('api/check-board-short-name', {params: {name: name.toUpperCase()}}).then(extractData).then(function (res) {
22                    return res === true;
23                });
24            },
25
26            update: function (board) {
27                return $http.post('api/board/' + board.shortName, {
28                    name: board.name,
29                    description: board.description,
30                    isArchived: board.archived
31                }).then(extractData);
32            },
33
34            // TODO column: move to another service
35
36            column: function (id) {
37                return $http.get('api/column/' + id).then(extractData);
38            },
39
40            moveColumnToLocation: function (id, location) {
41                return $http.post('api/column/' + id + '/to-location/' + location).then(extractData);
42            },
43
44            columns: function (shortName) {
45                return $http.get('api/board/' + shortName + '/columns-in').then(extractData);
46            },
47
48            columnsByLocation: function (shortName, location) {
49                return $http.get('api/board/' + shortName + '/columns-in/' + location).then(extractData);
50            },
51
52            createColumn: function (shortName, createColumn) {
53                return $http.post('api/board/' + shortName + '/column',
54                    createColumn).then(extractData);
55            },
56
57            reorderColumn: function (shortName, location, orderedColumnId) {
58                return $http.post('api/board/' + shortName + '/columns-in/' + location + '/column/order',
59                    orderedColumnId).then(extractData);
60            },
61
62            // FIXME remove shortName parameter
63            renameColumn: function (shortName, columnId, newName) {
64                return $http.post(
65                    'api/column/' + columnId + '/rename/' + newName).then(extractData);
66            },
67
68            // FIXME remove shortName parameter
69            redefineColumn: function (shortName, columnId, definition) {
70                return $http.post(
71                    'api/column/' + columnId + '/redefine/' + definition).then(extractData);
72            },
73
74            cardsInLocationPaginated: function (shortName, location, page) {
75                return $http.get('api/board/' + shortName + '/cards-in/' + location + '/' + page).then(extractData);
76            },
77
78            createCard: function (columnId, createCard) {
79                return $http.post('api/column/' + columnId + '/card', createCard).then(extractData);
80            },
81
82            createCardFromTop: function (columnId, createCard) {
83                return $http.post('api/column/' + columnId + '/card-top', createCard).then(extractData);
84            },
85
86            moveCardToColumn: function (cardId, previousColumnId, newColumnId, columnOrders) {
87                return $http.post('api/card/' + cardId + '/from-column/' + previousColumnId + '/to-column/' + newColumnId, columnOrders)
88                    .then(extractData);
89            },
90
91            moveCardToColumnEnd: function (cardId, previousColumnId, newColumnId) {
92                return $http.post('api/card/' + cardId + '/from-column/' + previousColumnId + '/to-column/' + newColumnId + '/end')
93                    .then(extractData);
94            },
95
96            // FIXME remove shortName parameter
97            updateCardOrder: function (shortName, columnId, cardIds) {
98                return $http.post('api/column/' + columnId + '/order', cardIds).then(extractData);
99            },
100
101            // FIXME remove shortName parameter
102            taskStatistics: function (shortName) {
103                return $http.get('api/board/' + shortName + '/task-statistics').then(extractData);
104            },
105
106            // FIXME remove shortName parameter
107            statistics: function (shortName, days) {
108                return $http.get('api/board/' + shortName + '/statistics/' + days).then(extractData);
109            }
110        };
111    });
112}());
113
Full Screen

card.js

Source: card.js Github

copy
1(function () {
2    'use strict';
3
4    var services = angular.module('lavagna.services');
5
6    var extractData = function (data) {
7        return data.data;
8    };
9
10    var extractActionLists = function (data) {
11        var rawData = data.data;
12        var actionLists = {lists: [], items: {}};
13
14        for (var i = 0; i < rawData.length; i++) {
15            // if it's a list, push it to the array
16            if (rawData[i].type === 'ACTION_LIST') { actionLists.lists.push(rawData[i]); }
17            // if it's an item, check if the array already exists, and then push into it
18            if (rawData[i].type === 'ACTION_CHECKED' || rawData[i].type === 'ACTION_UNCHECKED') {
19                if (actionLists.items[rawData[i].referenceId] === undefined) { actionLists.items[rawData[i].referenceId] = []; }
20                actionLists.items[rawData[i].referenceId].push(rawData[i]);
21            }
22        }
23
24        return actionLists;
25    };
26
27    var isInCardLabels = function (cardLabels, labelName, currentUserId) {
28        if (cardLabels === undefined || cardLabels.length === 0) { return false; } // empty, no labels at all
29        for (var i = 0; i < cardLabels.length; i++) {
30            if (cardLabels[i].labelName === labelName && cardLabels[i].labelDomain === 'SYSTEM' && cardLabels[i].value.valueUser === currentUserId) {
31                return true;
32            }
33        }
34
35        return false;
36    };
37
38    // FIXME: useless parameters, check one by one
39    services.factory('Card', function ($http, $window, FileUploader) {
40        return {
41            findCardByBoardShortNameAndSeqNr: function (shortName, seqNr) {
42                return $http.get('api/card-by-seq/' + shortName + '-' + seqNr).then(extractData);
43            },
44            findCardById: function (id) {
45                return $http.get('api/card/' + id).then(extractData);
46            },
47            findCardsByMilestone: function (projectName) {
48                function insertStatusIfExists(milestone, source, target, status) {
49                    if (source[status] !== undefined) {
50                        target[target.length] = {status: status, count: source[status]};
51                        milestone.totalCards += source[status];
52                    }
53                }
54
55                function orderByStatus(milestone) {
56                    milestone.totalCards = 0;
57                    var sorted = [];
58
59                    insertStatusIfExists(milestone, milestone.cardsCountByStatus, sorted, 'BACKLOG');
60                    insertStatusIfExists(milestone, milestone.cardsCountByStatus, sorted, 'OPEN');
61                    insertStatusIfExists(milestone, milestone.cardsCountByStatus, sorted, 'DEFERRED');
62                    insertStatusIfExists(milestone, milestone.cardsCountByStatus, sorted, 'CLOSED');
63
64                    return sorted;
65                }
66
67                return $http.get('api/project/' + projectName + '/cards-by-milestone').then(extractData).then(function (response) {
68                    response.cardsCountByStatus = {};
69
70                    angular.forEach(response.milestones, function (milestone) {
71                        response.cardsCountByStatus[milestone.labelListValue.id] = orderByStatus(milestone);
72                    });
73
74                    return response;
75                });
76            },
77            findCardsByMilestoneDetail: function (projectName, milestoneId) {
78                return $http.get('api/project/' + projectName + '/cards-by-milestone-detail/' + milestoneId).then(extractData);
79            },
80            findByColumn: function (columnId) {
81                return $http.get('api/column/' + columnId + '/card').then(extractData);
82            },
83            moveAllFromColumnToLocation: function (columnId, cardIds, location) {
84                return $http.post('api/card/from-column/' + columnId + '/to-location/' + location, {cardIds: cardIds}).then(extractData);
85            },
86            update: function (id, name) {
87                return $http.post('api/card/' + id, {name: name}).then(extractData);
88            },
89            description: function (id) {
90                return $http.get('api/card/' + id + '/description').then(extractData);
91            },
92            clone: function (cardId, columnId) {
93                return $http.post('api/card/' + cardId + '/clone-to/column/' + columnId).then(extractData);
94            },
95
96            updateDescription: function (id, description) {
97                return $http.post('api/card/' + id + '/description', {content: description}).then(extractData);
98            },
99            comments: function (id) {
100                return $http.get('api/card/' + id + '/comments').then(extractData);
101            },
102            addComment: function (id, comment) {
103                return $http.post('api/card/' + id + '/comment', comment).then(extractData);
104            },
105
106            updateComment: function (commentId, comment) {
107                return $http.post('api/card-data/comment/' + commentId, comment).then(extractData);
108            },
109
110            deleteComment: function (commentId) {
111                return $http['delete']('api/card-data/comment/' + commentId).then(extractData);
112            },
113            undoDeleteComment: function (eventId) {
114                return $http.post('api/card-data/undo/' + eventId + '/comment', null).then(extractData);
115            },
116            //
117
118            actionLists: function (id) {
119                return $http.get('api/card/' + id + '/actionlists').then(extractActionLists);
120            },
121
122            addActionList: function (id, actionList) {
123                return $http.post('api/card/' + id + '/actionlist', {content: actionList}).then(extractData);
124            },
125
126            updateActionList: function (itemId, content) {
127                return $http.post('api/card-data/actionlist/' + itemId + '/update', {content: content}).then(extractData);
128            },
129
130            deleteActionList: function (itemId) {
131                return $http['delete']('api/card-data/actionlist/' + itemId).then(extractData);
132            },
133
134            undoDeleteActionList: function (eventId) {
135                return $http.post('api/card-data/undo/' + eventId + '/actionlist', null).then(extractData);
136            },
137
138            addActionItem: function (referenceId, actionItem) {
139                return $http.post('api/card-data/actionlist/' + referenceId + '/item', {content: actionItem}).then(extractData);
140            },
141            toggleActionItem: function (itemId, status) {
142                return $http.post('api/card-data/actionitem/' + itemId + '/toggle/' + status, null).then(extractData);
143            },
144            updateActionItem: function (itemId, content) {
145                return $http.post('api/card-data/actionitem/' + itemId + '/update', {content: content}).then(extractData);
146            },
147            deleteActionItem: function (itemId) {
148                return $http['delete']('api/card-data/actionitem/' + itemId).then(extractData);
149            },
150            undoDeleteActionItem: function (eventId) {
151                return $http.post('api/card-data/undo/' + eventId + '/actionitem', null).then(extractData);
152            },
153            updateActionItemOrder: function (listId, order) {
154                return $http.post('api/card-data/actionlist/' + listId + '/order', order).then(extractData);
155            },
156            updateActionListOrder: function (cardId, order) {
157                return $http.post('api/card/' + cardId + '/order/actionlist', order).then(extractData);
158            },
159            moveActionItem: function (itemId, newActionList, sortedActionLists) {
160                return $http.post('api/card-data/actionitem/' + itemId + '/move-to-actionlist/' + newActionList, sortedActionLists).then(extractData);
161            },
162            files: function (id) {
163                return $http.get('api/card/' + id + '/files').then(extractData);
164            },
165            getMaxFileSize: function () {
166                return $http.get('api/configuration/max-upload-file-size').then(extractData);
167            },
168            getFileUploader: function (cardId) {
169                return new FileUploader({
170                    url: 'api/card/' + cardId + '/file',
171                    alias: 'files',
172                    autoUpload: true,
173                    headers: { 'x-csrf-token': $window.csrfToken }
174                });
175            },
176            getNewCardFileUploader: function () {
177                return new FileUploader({
178                    url: 'api/card/file',
179                    alias: 'files',
180                    autoUpload: true,
181                    headers: { 'x-csrf-token': $window.csrfToken }
182                });
183            },
184            deleteFile: function (cardDataId) {
185                return $http['delete']('api/card-data/file/' + cardDataId, null).then(extractData);
186            },
187
188            undoDeleteFile: function (eventId) {
189                return $http.post('api/card-data/undo/' + eventId + '/file').then(extractData);
190            },
191            activity: function (cardId) {
192                return $http.get('api/card/' + cardId + '/activity').then(extractData);
193            },
194
195            activityData: function (id) {
196                return $http.get('api/card-data/activity/' + id).then(extractData);
197            },
198
199            isWatchedByUser: function (labels, userId) {
200                return isInCardLabels(labels, 'WATCHED_BY', userId);
201            },
202
203            isAssignedToUser: function (labels, userId) {
204                return isInCardLabels(labels, 'ASSIGNED', userId);
205            }
206        };
207    });
208}());
209
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Jest on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)