woocommerce/packages/js/e2e-core-tests/specs/api/telemetry.test.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* Internal dependencies
*/
2021-10-14 22:11:59 +00:00
const { HTTPClientFactory } = require( '@woocommerce/api' );
/**
* External dependencies
*/
const config = require( 'config' );
const {
it,
describe,
beforeAll,
} = require( '@jest/globals' );
/**
* Create the default coupon and tests interactions with it via the API.
*/
const runTelemetryAPITest = () => {
describe( 'REST API > Telemetry', () => {
let client;
beforeAll(async () => {
const admin = config.get( 'users.admin' );
const url = config.get( 'url' );
client = HTTPClientFactory.build( url )
.withBasicAuth( admin.username, admin.password )
.withIndexPermalinks()
.create();
} );
it.each([
null,
{},
{ platform: 'ios' },
{ version: '1.1' },
])( 'errors for invalid request body - %p', async data => {
const response = await client
2021-10-13 15:10:03 +00:00
.post( `/wc-telemetry/tracker`, data )
.catch( err => {
2021-10-14 23:17:50 +00:00
expect( err.response.status ).toBe( 400 );
} );
expect( response ).toBeUndefined();
} );
it( 'returns 200 with correct fields', async () => {
const response = await client
2021-10-13 15:10:03 +00:00
.post( `/wc-telemetry/tracker`, {
platform: 'ios',
version: '1.0',
})
2021-10-14 23:17:50 +00:00
expect( response.status ).toBe( 200 );
} );
} );
};
module.exports = runTelemetryAPITest;