Debian Codegraph @

tests/api-testing/action/ExternalLinks.js

raw symbols SCIP
1 'use strict';
2
3 const { action, assert, utils } = require( 'api-testing' );
4
5 describe( 'ExternalLinks', () => {
6 const page = utils.title( 'ExternalLinkTest_' );
7 const links = [
8 'http://example.org/search-me',
9 'http://www.example.org/some-page',
10 'ssh://example.org/'
11 ];
12
13 let alice;
14
15 before( async () => {
16 alice = await action.alice();
17
18 const text = links.reduce( ( currText, url ) => `${ currText } [${ url }]`, '' );
19
20 await alice.edit( page, { text } );
21 } );
22
23 it( 'can be listed', async () => {
24 const result = await alice.prop( 'extlinks', page );
25 const fetchedLinks = result[ page ].extlinks.map( ( p ) => p[ '*' ] );
26 assert.sameMembers( fetchedLinks, links );
27 } );
28
29 it( 'can be limited', async () => {
30 const result = await alice.prop( 'extlinks', page, { ellimit: 1 } );
31 const fetchedLinks = result[ page ].extlinks.map( ( p ) => p[ '*' ] );
32 assert.equal( fetchedLinks.length, 1 );
33 } );
34
35 it( 'can be filtered by protocol', async () => {
36 const result = await alice.prop( 'extlinks', page, { elprotocol: 'ssh' } );
37 const fetchedLinks = result[ page ].extlinks.map( ( p ) => p[ '*' ] );
38 assert.sameMembers( fetchedLinks, [ 'ssh://example.org/' ] );
39 } );
40
41 it( 'throws an error on invalid protocol', async () => {
42 const result = await alice.actionError(
43 'query',
44 {
45 prop: 'extlinks',
46 titles: page,
47 elprotocol: 'uwu'
48 }
49 );
50 assert.deepNestedInclude( result, { code: 'badvalue' } );
51 } );
52
53 it( 'can be filtered by search string', async () => {
54 const result = await alice.prop( 'extlinks', page, { elquery: 'example.org/search-me' } );
55 const fetchedLinks = result[ page ].extlinks.map( ( p ) => p[ '*' ] );
56 assert.sameMembers( fetchedLinks, [ 'http://example.org/search-me' ] );
57 } );
58
59 it( 'does not expand external urls', async () => {
60 const result = await alice.prop( 'extlinks', page, { elexpandurl: true } );
61 const fetchedLinks = result[ page ].extlinks.map( ( p ) => p[ '*' ] );
62 assert.sameMembers( fetchedLinks, links );
63 } );
64 } );