Skip to content

Commit

Permalink
fix(spec): update sources spec (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Bodin authored Feb 10, 2022
1 parent 1188f69 commit a26d4b5
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { PostURLJobInput } from './postURLJobInput';
import type { PostURLJobTarget } from './postURLJobTarget';

/**
* Object containing a URL job.
Expand All @@ -8,7 +9,12 @@ export type PostURLJob = {
* The type of the file to ingest.
*/
type: PostURLJobType;
/**
* The name of the column that hold the unique identifier.
*/
uniqueIDColumn?: string;
input: PostURLJobInput;
target: PostURLJobTarget;
};

export type PostURLJobType = 'csv';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* The authentication scheme for the URL that will be fetched.
*/
export type PostURLJobAuth = {
/**
* The type of authentication to use.
*/
type: PostURLJobAuthType;
/**
* The login to use for Basic Auth.
*/
login: string;
/**
* The password to use for Basic Auth.
*/
password: string;
};

export type PostURLJobAuthType = 'basic';
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PostURLJobAuth } from './postURLJobAuth';

/**
* The input of the job.
*/
Expand All @@ -6,4 +8,11 @@ export type PostURLJobInput = {
* The URL of the file to ingest.
*/
url: string;
/**
* The HTTP method that will be used to fetch the URL.
*/
method?: PostURLJobInputMethod;
auth?: PostURLJobAuth;
};

export type PostURLJobInputMethod = 'GET' | 'POST';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* The target of the job.
*/
export type PostURLJobTarget = {
/**
* The product to target.
*/
type: PostURLJobTargetType;
/**
* The index name of the product.
*/
indexName: string;
/**
* The type of operation to execute.
*/
operation: PostURLJobTargetOperation;
};

export type PostURLJobTargetType = 'search';

export type PostURLJobTargetOperation = 'replace';
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export const createSourcesApi = (
'Parameter `postURLJob.input` is required when calling `postIngestUrl`.'
);
}
if (!postURLJob.target) {
throw new Error(
'Parameter `postURLJob.target` is required when calling `postIngestUrl`.'
);
}

const request: Request = {
method: 'POST',
Expand Down
62 changes: 61 additions & 1 deletion specs/sources/paths/ingest/postUrl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,82 @@ post:
required:
- type
- input
- target
properties:
type:
type: string
description: The type of the file to ingest.
enum:
- csv
uniqueIDColumn:
type: string
description: The name of the column that hold the unique identifier
example: objectID
input:
type: object
title: postURLJobInput
description: The input of the job.
additionalProperties: false
required:
- url
properties:
url:
type: string
description: The URL of the file to ingest.
method:
type: string
description: The HTTP method that will be used to fetch the URL.
default: GET
enum:
- GET
- POST
auth:
type: object
title: postURLJobAuth
description: The authentication scheme for the URL that will be fetched.
additionalProperties: false
required:
- type
- login
- password
properties:
type:
type: string
description: The type of authentication to use.
enum:
- basic
login:
type: string
description: The login to use for Basic Auth.
example: johndoe
password:
type: string
description: The password to use for Basic Auth.
example: mypassword
target:
type: object
title: postURLJobTarget
description: The target of the job.
additionalProperties: false
required:
- url
- type
- indexName
- operation
properties:
type:
type: string
description: The product to target
enum:
- search
indexName:
type: string
description: The index name of the product
example: my_index_name
operation:
type: string
description: The type of operation to execute
enum:
- replace
responses:
'200':
description: OK
Expand Down
42 changes: 39 additions & 3 deletions tests/CTS/client/sources/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
"type": "method",
"object": "$client",
"path": "postIngestUrl",
"parameters": [{ "type": "csv", "input": { "url": "..." } }],
"parameters": [
{
"type": "csv",
"input": {
"url": "https://example.com/file.csv"
},
"target": {
"type": "search",
"indexName": "pageviews",
"operation": "replace"
}
}
],
"expected": {
"match": {
"objectContaining": {
Expand All @@ -24,7 +36,19 @@
"type": "method",
"object": "$client",
"path": "postIngestUrl",
"parameters": [{ "type": "csv", "input": { "url": "..." } }],
"parameters": [
{
"type": "csv",
"input": {
"url": "https://example.com/file.csv"
},
"target": {
"type": "search",
"indexName": "pageviews",
"operation": "replace"
}
}
],
"expected": {
"testSubject": "actual.userAgent",
"match": {
Expand All @@ -41,7 +65,19 @@
"type": "method",
"object": "$client",
"path": "postIngestUrl",
"parameters": [{ "type": "csv", "input": { "url": "..." } }],
"parameters": [
{
"type": "csv",
"input": {
"url": "https://example.com/file.csv"
},
"target": {
"type": "search",
"indexName": "pageviews",
"operation": "replace"
}
}
],
"expected": {
"match": {
"objectContaining": {
Expand Down
54 changes: 54 additions & 0 deletions tests/CTS/methods/requests/sources/postIngestUrl.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"type": "csv",
"input": {
"url": "https://example.com/file.csv"
},
"target": {
"type": "search",
"indexName": "pageviews",
"operation": "replace"
}
},
"request": {
Expand All @@ -15,6 +20,55 @@
"type": "csv",
"input": {
"url": "https://example.com/file.csv"
},
"target": {
"type": "search",
"indexName": "pageviews",
"operation": "replace"
}
}
}
},
{
"method": "postIngestUrl",
"testName": "post postIngestUrl with all parameters",
"parameters": {
"type": "csv",
"uniqueIDColumn": "foobar",
"input": {
"url": "https://example.com/file.csv",
"method": "POST",
"auth": {
"type": "basic",
"login": "johndoe",
"password": "password"
}
},
"target": {
"type": "search",
"indexName": "pageviews",
"operation": "replace"
}
},
"request": {
"path": "/1/ingest/url",
"method": "POST",
"data": {
"type": "csv",
"uniqueIDColumn": "foobar",
"input": {
"url": "https://example.com/file.csv",
"method": "POST",
"auth": {
"type": "basic",
"login": "johndoe",
"password": "password"
}
},
"target": {
"type": "search",
"indexName": "pageviews",
"operation": "replace"
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions tests/output/javascript/src/client/sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ describe('api', () => {

let actual;

actual = $client.postIngestUrl({ type: 'csv', input: { url: '...' } });
actual = $client.postIngestUrl({
type: 'csv',
input: { url: 'https://example.com/file.csv' },
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
});

if (actual instanceof Promise) {
actual = await actual;
Expand All @@ -35,7 +39,11 @@ describe('api', () => {

let actual;

actual = $client.postIngestUrl({ type: 'csv', input: { url: '...' } });
actual = $client.postIngestUrl({
type: 'csv',
input: { url: 'https://example.com/file.csv' },
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
});

if (actual instanceof Promise) {
actual = await actual;
Expand All @@ -52,7 +60,11 @@ describe('api', () => {

let actual;

actual = $client.postIngestUrl({ type: 'csv', input: { url: '...' } });
actual = $client.postIngestUrl({
type: 'csv',
input: { url: 'https://example.com/file.csv' },
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
});

if (actual instanceof Promise) {
actual = await actual;
Expand Down
29 changes: 29 additions & 0 deletions tests/output/javascript/src/methods/requests/sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,42 @@ describe('postIngestUrl', () => {
const req = (await client.postIngestUrl({
type: 'csv',
input: { url: 'https://example.com/file.csv' },
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
})) as unknown as EchoResponse;

expect(req.path).toEqual('/1/ingest/url');
expect(req.method).toEqual('POST');
expect(req.data).toEqual({
type: 'csv',
input: { url: 'https://example.com/file.csv' },
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
});
expect(req.searchParams).toEqual(undefined);
});

test('post postIngestUrl with all parameters', async () => {
const req = (await client.postIngestUrl({
type: 'csv',
uniqueIDColumn: 'foobar',
input: {
url: 'https://example.com/file.csv',
method: 'POST',
auth: { type: 'basic', login: 'johndoe', password: 'password' },
},
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
})) as unknown as EchoResponse;

expect(req.path).toEqual('/1/ingest/url');
expect(req.method).toEqual('POST');
expect(req.data).toEqual({
type: 'csv',
uniqueIDColumn: 'foobar',
input: {
url: 'https://example.com/file.csv',
method: 'POST',
auth: { type: 'basic', login: 'johndoe', password: 'password' },
},
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
});
expect(req.searchParams).toEqual(undefined);
});
Expand Down

0 comments on commit a26d4b5

Please sign in to comment.