diff --git a/test/helpers/WDIOWikibaseApiPatch.js b/test/helpers/WDIOWikibaseApiPatch.js deleted file mode 100644 index 3a6a26ff7..000000000 --- a/test/helpers/WDIOWikibaseApiPatch.js +++ /dev/null @@ -1,164 +0,0 @@ -import MWBot from 'mwbot'; -import request from 'request'; - -/** - * Patches the use of `browser.config` in - * https://github.com/wmde/wdio-wikibase/blob/master/wikibase.api.js - * TODO: Update wdio-wikibase, remove this file. - * See https://phabricator.wikimedia.org/T346623 - */ -class WikibaseApiPatch { - /** - * Initialize the API - * - * @param {string} [cpPosIndex] The value of the cpPosIndex browser cookie. - * Optional, but strongly recommended to have chronology protection. - * @return {Promise} resolving with MWBot - */ - async initialize( cpPosIndex ) { - const config = browser.options; - - const jar = request.jar(); - if ( cpPosIndex ) { - const cookie = request.cookie( `cpPosIndex=${cpPosIndex}` ); - jar.setCookie( cookie, config.baseUrl ); - } - const bot = new MWBot( - { apiUrl: `${config.baseUrl}/api.php` }, - { jar: jar } - ); - const loginCredentials = { - username: process.env.MW_ADMIN_NAME, - password: process.env.MW_ADMIN_PASS - }; - await bot.loginGetEditToken( loginCredentials ); - this.bot = bot; - - return bot; - } - - /** - * @return {Promise} resolving with MWBot - */ - getBot() { - if ( !this.bot ) { - console.trace( 'WARNING: WikibaseApi not initialized' ); - return this.initialize(); - } - - return Promise.resolve( this.bot ); - } - - /** - * Create an item - * - * @param {string|Object} [label] Optional English label of the item or object - * containing all labels - * @param {Object} [data] Optional data to populate the item with - * @return {Promise} resolving with the id of the created item - */ - async createItem( label, data ) { - const itemData = {}; - let labels = {}; - - if ( typeof label === 'object' ) { - labels = label; - } else if ( label ) { - labels = { - en: { - language: 'en', - value: label - } - }; - } - - Object.assign( itemData, { labels }, data ); - - const bot = await this.getBot(); - - const response = await bot.request( { - action: 'wbeditentity', - new: 'item', - data: JSON.stringify( itemData ), - token: bot.editToken - } ); - - return response.entity.id; - } - - /** - * Create a property - * - * @param {string} datatype The datatype of the property - * @param {Object} [data] Optional data to populate the property with - * @return {Promise} resolving with the id of the created property - */ - async createProperty( datatype, data ) { - let propertyData = {}; - - propertyData = Object.assign( {}, { datatype }, data ); - - const bot = await this.getBot(); - const response = await bot.request( { - action: 'wbeditentity', - new: 'property', - data: JSON.stringify( propertyData ), - token: bot.editToken - } ); - - return response.entity.id; - } - - /** - * @param {string} id The id of the entity - * @return {Promise} resolving with the requested entity - */ - async getEntity( id ) { - const bot = await this.getBot(); - const response = await bot.request( { - ids: id, - action: 'wbgetentities', - token: bot.editToken - } ); - return response.entities[ id ]; - } - - /** - * @param {string} entityId The id of the entity - * @return {Promise} - */ - async protectEntity( entityId ) { - const bot = await this.getBot(); - - const getEntitiesResponse = await bot.request( { - action: 'wbgetentities', - format: 'json', - ids: entityId, - props: 'info' - } ); - const entityTitle = getEntitiesResponse.entities[ entityId ].title; - return bot.request( { - action: 'protect', - title: entityTitle, - protections: 'edit=sysop', - token: bot.editToken - } ); - } - - /** - * @param {string} datatype - * @return {Promise} resolving with the id of the property - */ - async getProperty( datatype ) { - const envName = `WIKIBASE_PROPERTY_${datatype.toUpperCase()}`; - if ( envName in process.env ) { - return process.env[ envName ]; - } else { - const propertyId = await this.createProperty( datatype ); - process.env[ envName ] = propertyId; - return propertyId; - } - } -} - -export default new WikibaseApiPatch(); diff --git a/test/helpers/default-functions.ts b/test/helpers/default-functions.ts index 788ebe560..1c552060f 100644 --- a/test/helpers/default-functions.ts +++ b/test/helpers/default-functions.ts @@ -2,7 +2,7 @@ import axios, { AxiosResponse } from 'axios'; import assert from 'assert'; import { exec } from 'child_process'; import lodash from 'lodash'; -import WikibaseApi from './WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import BotResponse from './types/bot-response.js'; import DatabaseConfig from './types/database-config.js'; import LuaCPUValue from './types/lua-cpu-value.js'; diff --git a/test/specs/elasticsearch/elasticsearch.ts b/test/specs/elasticsearch/elasticsearch.ts index c6dcaccda..2e63ff7f2 100644 --- a/test/specs/elasticsearch/elasticsearch.ts +++ b/test/specs/elasticsearch/elasticsearch.ts @@ -1,6 +1,6 @@ import assert from 'assert'; import { getTestString } from 'wdio-mediawiki/Util.js'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import SearchResult from '../../helpers/types/search-result.js'; const itemAlias: string = getTestString( 'alias' ); diff --git a/test/specs/fedprops/item.ts b/test/specs/fedprops/item.ts index d92d6743e..05aca424e 100644 --- a/test/specs/fedprops/item.ts +++ b/test/specs/fedprops/item.ts @@ -2,7 +2,7 @@ import { getTestString } from 'wdio-mediawiki/Util.js'; import assert from 'assert'; import QueryServiceUI from '../../helpers/pages/queryservice-ui/queryservice-ui.page.js'; import ItemPage from 'wdio-wikibase/pageobjects/item.page.js'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import { AxiosError } from 'axios'; describe( 'Fed props Item', function () { diff --git a/test/specs/fedprops/prefetching.ts b/test/specs/fedprops/prefetching.ts index 43f3a98ef..939a1077b 100644 --- a/test/specs/fedprops/prefetching.ts +++ b/test/specs/fedprops/prefetching.ts @@ -1,6 +1,6 @@ import { getTestString } from 'wdio-mediawiki/Util.js'; import assert from 'assert'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; describe( 'Property Prefetching', function () { let itemId: string; diff --git a/test/specs/quickstatements/quickstatements.ts b/test/specs/quickstatements/quickstatements.ts index 9547dd150..9e0ff440e 100644 --- a/test/specs/quickstatements/quickstatements.ts +++ b/test/specs/quickstatements/quickstatements.ts @@ -1,6 +1,6 @@ import assert from 'assert'; import lodash from 'lodash'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import { AxiosResponse } from 'axios'; type ReferenceValue = { diff --git a/test/specs/repo/api.ts b/test/specs/repo/api.ts index 6e48c7160..b069f4bf1 100644 --- a/test/specs/repo/api.ts +++ b/test/specs/repo/api.ts @@ -1,6 +1,6 @@ import assert from 'assert'; import { getTestString } from 'wdio-mediawiki/Util.js'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; describe( 'Wikibase API', function () { it( 'Should be able to create many properties and items', async () => { diff --git a/test/specs/repo/extensions/wikibase-edtf.ts b/test/specs/repo/extensions/wikibase-edtf.ts index 3d670ef71..13f1d0e24 100644 --- a/test/specs/repo/extensions/wikibase-edtf.ts +++ b/test/specs/repo/extensions/wikibase-edtf.ts @@ -1,6 +1,6 @@ import assert from 'assert'; import { skipIfExtensionNotPresent } from '../../../helpers/default-functions.js'; -import WikibaseApi from '../../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; describe( 'WikibaseEdtf', function () { beforeEach( async function () { diff --git a/test/specs/repo/extensions/wikibase-local-media.ts b/test/specs/repo/extensions/wikibase-local-media.ts index 546d93162..ece309728 100644 --- a/test/specs/repo/extensions/wikibase-local-media.ts +++ b/test/specs/repo/extensions/wikibase-local-media.ts @@ -1,7 +1,7 @@ import assert from 'assert'; import SuiteLoginPage from '../../../helpers/pages/SuiteLoginPage.js'; import { skipIfExtensionNotPresent } from '../../../helpers/default-functions.js'; -import WikibaseApi from '../../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; describe( 'WikibaseLocalMedia', function () { let propertyId: string; diff --git a/test/specs/repo/property.ts b/test/specs/repo/property.ts index 14c74d27e..9f60ffe72 100644 --- a/test/specs/repo/property.ts +++ b/test/specs/repo/property.ts @@ -1,6 +1,6 @@ import assert from 'assert'; import Property from '../../helpers/pages/entity/property.page.js'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; describe( 'Property', function () { let propertyId = null; diff --git a/test/specs/repo/queryservice.ts b/test/specs/repo/queryservice.ts index 1398901aa..6ac4191a5 100644 --- a/test/specs/repo/queryservice.ts +++ b/test/specs/repo/queryservice.ts @@ -3,7 +3,7 @@ import assert from 'assert'; import QueryServiceUI from '../../helpers/pages/queryservice-ui/queryservice-ui.page.js'; import SuiteLoginPage from '../../helpers/pages/SuiteLoginPage.js'; import { stringify } from 'querystring'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; describe( 'QueryService', () => { it( 'Should not be able to post to sparql endpoint', async () => { diff --git a/test/specs/repo/search.ts b/test/specs/repo/search.ts index c35a1e6ff..d44069e24 100644 --- a/test/specs/repo/search.ts +++ b/test/specs/repo/search.ts @@ -1,5 +1,5 @@ import assert from 'assert'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; describe( 'Search', function () { it( 'Should be able to create an item and search for it', async () => { diff --git a/test/specs/repo_client/extensions/scribunto-item.ts b/test/specs/repo_client/extensions/scribunto-item.ts index cfc5a554c..b2bbbf84b 100644 --- a/test/specs/repo_client/extensions/scribunto-item.ts +++ b/test/specs/repo_client/extensions/scribunto-item.ts @@ -5,7 +5,7 @@ import { stringify } from 'querystring'; import { readFile } from 'fs/promises'; import { skipIfExtensionNotPresent } from '../../../helpers/default-functions.js'; import { utf8 } from '../../../helpers/readFileEncoding.js'; -import WikibaseApi from '../../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import ExternalChange from '../../../helpers/types/external-change.js'; const itemLabel = getTestString( 'The Item' ); diff --git a/test/specs/repo_client/item.ts b/test/specs/repo_client/item.ts index 7ceee2c47..b9a867879 100644 --- a/test/specs/repo_client/item.ts +++ b/test/specs/repo_client/item.ts @@ -2,7 +2,7 @@ import { getTestString } from 'wdio-mediawiki/Util.js'; import assert from 'assert'; import SuiteLoginPage from '../../helpers/pages/SuiteLoginPage.js'; import { stringify } from 'querystring'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import ExternalChange from '../../helpers/types/external-change.js'; const itemLabel = getTestString( 'The Item' ); diff --git a/test/specs/upgrade/pre-upgrade.ts b/test/specs/upgrade/pre-upgrade.ts index 93e34cde1..d21e4f533 100644 --- a/test/specs/upgrade/pre-upgrade.ts +++ b/test/specs/upgrade/pre-upgrade.ts @@ -1,5 +1,5 @@ import assert from 'assert'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; describe( 'Wikibase pre upgrade', function () { it( 'Should be able to create a specific item', async () => { diff --git a/test/specs/upgrade/queryservice-post-upgrade.ts b/test/specs/upgrade/queryservice-post-upgrade.ts index 1d827da0a..2f73d0638 100644 --- a/test/specs/upgrade/queryservice-post-upgrade.ts +++ b/test/specs/upgrade/queryservice-post-upgrade.ts @@ -1,7 +1,7 @@ import assert from 'assert'; import { getElementByURI } from '../../helpers/blazegraph.js'; import Binding from '../../helpers/types/binding.js'; -import WikibaseApi from '../../helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; describe( 'Wikibase post upgrade', function () { const itemLabel = 'NewUpgradeItem'; diff --git a/test/wdio.conf.ts b/test/wdio.conf.ts index 7083c9957..6e18c4600 100755 --- a/test/wdio.conf.ts +++ b/test/wdio.conf.ts @@ -7,7 +7,7 @@ import { existsSync, mkdir, rm } from 'fs'; import JsonReporter from './helpers/json-reporter.js'; import { defaultFunctions as defaultFunctionsInit } from './helpers/default-functions.js'; import saveScreenshot from './helpers/WDIOMediawikiScreenshotPatch.js'; -import WikibaseApi from './helpers/WDIOWikibaseApiPatch.js'; +import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import { Options, Frameworks } from '@wdio/types'; const resultsDir = process.env.RESULTS_DIR;