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