Debian Codegraph @

tests/api-testing/action/Tag.js

raw symbols SCIP
1 'use strict';
2
3 const { action, utils, assert, wiki } = require( 'api-testing' );
4
5 describe( 'The tag action module', () => {
6
7 const tagName = 'foo-bar';
8 const tag2Name = 'foo-bar-baz';
9 const reason = 'For testing tags';
10 let bob;
11 let revisionId, recentChangeId;
12 let page, pageId;
13
14 before( async () => {
15 bob = await action.bob();
16 page = utils.title( 'Tag_' );
17 await action.makeTag( tagName );
18 await action.makeTag( tag2Name );
19 await bob.edit( page, { text: 'Revision to tag' } );
20 await wiki.runAllJobs();
21 const recentChange = await bob.getChangeEntry(
22 { rctitle: page }
23 );
24 pageId = recentChange.pageid;
25 revisionId = recentChange.revid;
26 recentChangeId = recentChange.rcid;
27 } );
28
29 it( 'Adds and removes tags from revision', async () => {
30 // Add a tag to revision
31 await bob.action( 'tag', {
32 revid: revisionId,
33 add: tagName,
34 token: bob.tokens.csrftoken,
35 reason
36 }, 'POST' );
37
38 const queryParams = {
39 prop: 'revisions',
40 revids: revisionId,
41 rvprop: 'tags'
42 };
43
44 // Query to make sure tag was saved
45 const { query: queryWithTags } = await bob.action( 'query', queryParams );
46
47 const { revisions: revsWithTags } = queryWithTags.pages[ pageId ];
48 assert.deepEqual( revsWithTags[ 0 ].tags, [ tagName ] );
49
50 // Remove tag
51 await bob.action( 'tag', {
52 revid: revisionId,
53 remove: tagName,
54 token: bob.tokens.csrftoken
55 }, 'POST' );
56 const { query: queryWithoutTags } = await bob.action( 'query', queryParams );
57 const { revisions: revsWithoutTags } = queryWithoutTags.pages[ pageId ];
58
59 // Query to make sure no tag remains
60 assert.deepEqual( revsWithoutTags[ 0 ].tags, [] );
61 } );
62
63 it( 'Adds and removes tags from recent change', async () => {
64 // Add 2 tags to recent change
65 await bob.action( 'tag', {
66 rcid: recentChangeId,
67 add: `${ tagName }|${ tag2Name }`,
68 token: bob.tokens.csrftoken,
69 reason
70 }, 'POST' );
71
72 const queryParams = {
73 rctitle: page,
74 rcprop: 'tags'
75 };
76
77 // Query to make sure tag was saved
78 const recentChangeWithTag = await bob.list( 'recentchanges', queryParams );
79 assert.deepEqual( recentChangeWithTag[ 0 ].tags, [ tagName, tag2Name ] );
80
81 // Remove 1 of the tags
82 await bob.action( 'tag', {
83 rcid: recentChangeId,
84 remove: tagName,
85 token: bob.tokens.csrftoken
86 }, 'POST' );
87
88 // Query to make sure only 1 tag remains
89 const recentChangeWithoutTag = await bob.list( 'recentchanges', queryParams );
90 assert.deepEqual( recentChangeWithoutTag[ 0 ].tags, [ tag2Name ] );
91 } );
92
93 } );