Skip to content

Commit

Permalink
Fix bugfix add consent
Browse files Browse the repository at this point in the history
  • Loading branch information
rickypid committed Jan 6, 2022
1 parent 49e5f98 commit 4ca2274
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iubenda-consent-solution-api",
"version": "0.1.2",
"version": "0.1.3",
"description": "API client to implement Iubenda Consent Solution in backend service",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
37 changes: 36 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,42 @@ describe('iubenda-consent-solution-api', function () {
});

//ToDo implements createConsent()

it('Add Consent', async function () {
const client = new IubendaConsentSolution({apiKey: validApiKey});
const result = await client.createConsent({
autodetect_ip_address: 'false',
subject: {
id: '1',
email: 'test@test.it',
first_name: 'John',
last_name: 'Fix',
},
legal_notices: [
{identifier: 'privacy_policy',version: '1'},
{identifier: 'terms_and_conditions',version: '1'},
{identifier: 'cookie_policy',version: '1'},
],
proofs: [
{
content: '{}',
form: '<form></form>',
},
],
preferences: {
privacy_policy: 'true',
terms_and_conditions: 'true',
cookie_policy: 'true',
newsletter_subscription: 'false',
},
ip_address: '',
});
if ('error' in result) {
console.log(result);
expect.fail('Response error! ' + result.message);
}
else
expect(true);
});
});
describe('Subjects', function () {
it('Get Subjects', async function () {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface Consent {
/**
* Considered only when using a `private` key. Saves the passed IP address on the Consent. Default null
*/
ip_address?: null;
ip_address?: string;
/**
* Default `true`, Considered only when using a `public` key. Enables or disables (true, false) the IP address autedetection. Default true
*/
Expand Down Expand Up @@ -299,7 +299,7 @@ export class IubendaConsentSolution {
}

async createConsent(consent: ConsentExtended): Promise<ResponseError | ConsentPostResponse> {
return IubendaConsentSolution.sendRequest(await IubendaConsentSolution.sendRequest(this.addHeaders(post(this.generateUrl('consent')).send(consent))));
return await IubendaConsentSolution.sendRequest(this.addHeaders(post(this.generateUrl('consent')).send(consent)));
}

async getSubjects(query?: SubjectQueryParameters): Promise<ResponseError | SubjectResponse[]> {
Expand Down

0 comments on commit 4ca2274

Please sign in to comment.