Skip to content

Commit

Permalink
Merge pull request #271 from pactumjs/270-typescript-definition-for-i…
Browse files Browse the repository at this point in the history
…nteractiondetails-model-doesnt-include-all-properties

interaction type def
  • Loading branch information
ASaiAnudeep authored Mar 30, 2023
2 parents 73f548e + 78b0be4 commit c807267
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pactum",
"version": "3.3.2",
"version": "3.3.3",
"description": "REST API Testing Tool for all levels in a Test Pyramid",
"main": "./src/index.js",
"types": "./src/index.d.ts",
Expand Down
21 changes: 17 additions & 4 deletions src/exports/mock.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ export interface InteractionExpectations {
callCount?: number;
}

export interface InteractionCallRequest {
method?: string;
path?: string;
query?: object;
headers?: object;
body?: object;
}

export interface InteractionCall {
request?: InteractionCallRequest;
exercisedAt: number;
}

// TODO - accept function - (req, res)
export interface Interaction {
id?: string;
Expand All @@ -55,12 +68,12 @@ export interface Interaction {
response: InteractionResponse;
expects?: InteractionExpectations;
stores?: object;
calls?: InteractionCall[];
}

export interface InteractionDetails {
id: string;
exercised: boolean;
callCount: number;
export interface InteractionDetails extends Interaction {
exercised?: boolean;
callCount?: number;
}

export interface Handler {
Expand Down
2 changes: 1 addition & 1 deletion src/exports/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const mock = {
alone = false;
}
for (let j = 0; j < raw.length; j++) {
const interaction = new Interaction(raw[j], true);
const interaction = new Interaction(raw[j]);
this._server.addInteraction(interaction.id, interaction);
ids.push(interaction.id);
}
Expand Down
38 changes: 19 additions & 19 deletions test/unit/interaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Interaction', () => {
}
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('Interaction', () => {
}
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('Interaction', () => {
}
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('Interaction', () => {
}
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -264,7 +264,7 @@ describe('Interaction', () => {
}
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -318,7 +318,7 @@ describe('Interaction', () => {
},
response: function () { }
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction.request).deep.equals({
"method": "GET",
"path": "/api/projects/1",
Expand Down Expand Up @@ -346,7 +346,7 @@ describe('Interaction', () => {
fixedDelay: 10
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -406,7 +406,7 @@ describe('Interaction', () => {
}
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -469,7 +469,7 @@ describe('Interaction', () => {
}
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -525,7 +525,7 @@ describe('Interaction', () => {
}
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -581,7 +581,7 @@ describe('Interaction', () => {
}
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -621,7 +621,7 @@ describe('Interaction', () => {
path: '/api/projects/1'
}
};
const interaction = new Interaction(raw, true);
const interaction = new Interaction(raw);
expect(interaction).to.deep.equals({
"id": "random",
"callCount": 0,
Expand Down Expand Up @@ -664,7 +664,7 @@ describe('Interaction', () => {
}
}
};
expect(function () { new Interaction(raw, true); }).to.throws('`request.method` is required');
expect(function () { new Interaction(raw); }).to.throws('`request.method` is required');
});

it('invalid mock interaction - no request method', () => {
Expand All @@ -684,7 +684,7 @@ describe('Interaction', () => {
}
}
};
expect(function () { new Interaction(raw, true); }).to.throws('`request.method` is invalid');
expect(function () { new Interaction(raw); }).to.throws('`request.method` is invalid');
});

it('invalid mock interaction - no request path', () => {
Expand All @@ -703,7 +703,7 @@ describe('Interaction', () => {
}
}
};
expect(function () { new Interaction(raw, true); }).to.throws('`request.path` is required');
expect(function () { new Interaction(raw); }).to.throws('`request.path` is required');
});

it('invalid mock interaction - query as null', () => {
Expand All @@ -724,7 +724,7 @@ describe('Interaction', () => {
}
}
};
expect(function () { new Interaction(raw, true); }).to.throws('`request.queryParams` should be object');
expect(function () { new Interaction(raw); }).to.throws('`request.queryParams` should be object');
});

it('invalid mock interaction - query as string', () => {
Expand All @@ -745,7 +745,7 @@ describe('Interaction', () => {
}
}
};
expect(function () { new Interaction(raw, true); }).to.throws('`request.queryParams` should be object');
expect(function () { new Interaction(raw); }).to.throws('`request.queryParams` should be object');
});

it('invalid mock interaction - query as empty string', () => {
Expand All @@ -766,7 +766,7 @@ describe('Interaction', () => {
}
}
};
expect(function () { new Interaction(raw, true); }).to.throws('`request.queryParams` should be object');
expect(function () { new Interaction(raw); }).to.throws('`request.queryParams` should be object');
});

it('invalid mock interaction - query as array', () => {
Expand All @@ -787,7 +787,7 @@ describe('Interaction', () => {
}
}
};
expect(function () { new Interaction(raw, true); }).to.throws('`request.queryParams` should be object');
expect(function () { new Interaction(raw); }).to.throws('`request.queryParams` should be object');
});

it('invalid mock interaction - null', () => {
Expand Down

0 comments on commit c807267

Please sign in to comment.