This repository was archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathpact.service.ts
68 lines (54 loc) · 1.94 KB
/
pact.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { PactWeb } from '@pact-foundation/pact-web';
import { SkyAppConfig } from '@blackbaud/skyux-builder/runtime/config';
declare var Pact: any;
/**
* Wrapper service for pact-js functions to handle finding the correct pact server
*/
export class SkyPactService {
private pactProviders: { [providerName: string]: PactWeb } = {};
private matchersInternal: any;
constructor(private appConfig: SkyAppConfig) {
Object.keys(this.appConfig.runtime.pactConfig.providers).forEach((providerName: string) => {
this.pactProviders[providerName] =
new Pact.PactWeb(
{
host: this.appConfig.runtime.pactConfig.providers[providerName].host,
port: this.appConfig.runtime.pactConfig.providers[providerName].port
}
);
});
this.matchersInternal = Pact.Matchers;
}
/**
* Add an interaction to the Mock Service.
* @param provider The name of the provider service.
* @param interaction The provider interaction.
*/
public addInteraction(provider: string, interaction: any): Promise<string> {
return this.pactProviders[provider].addInteraction(interaction);
}
/**
* Clear up any interactions in the Mock Service.
* @param provider The name of the provider service.
*/
public removeInteractions(provider: string): Promise<string> {
return this.pactProviders[provider].removeInteractions();
}
/**
* Writes the Pact file and clears any interactions left behind.
* @param provider The name of the provider service.
*/
public finalize(provider: string): Promise<string> {
return this.pactProviders[provider].finalize();
}
/**
* Checks with the Mock Service if the expected interactions have been exercised.
* @param provider The name of the provider service.
*/
public verify(provider: string): Promise<string> {
return this.pactProviders[provider].verify();
}
public get matchers() {
return this.matchersInternal;
}
}