-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from Scalingo/feat/contract-agreements
feat: support for contracts and agreements
- Loading branch information
Showing
7 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
## Unreleased | ||
|
||
* nothing yet | ||
## 0.6.1 | ||
|
||
* feature: support for contracts and agreements | ||
|
||
## 0.6.0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Client } from ".."; | ||
import { Contract, ContractAgreement } from "../models/auth/contracts"; | ||
import { CreateAgreementParams } from "../params/auth/contracts"; | ||
import { unpackData } from "../utils"; | ||
|
||
/** | ||
* Contract and Agreements API Client | ||
*/ | ||
export default class Contracts { | ||
/** Scalingo API Client */ | ||
_client: Client; | ||
|
||
/** | ||
* Create a new "thematic" client | ||
* @param client Scalingo API Client | ||
*/ | ||
constructor(client: Client) { | ||
this._client = client; | ||
} | ||
|
||
/** | ||
* Get all existing contracts | ||
*/ | ||
all(): Promise<Contract[]> { | ||
return unpackData( | ||
this._client.authApiClient().get("/contracts"), | ||
"contracts" | ||
); | ||
} | ||
|
||
/** | ||
* Get all existing contract agreements | ||
*/ | ||
allAgreements(): Promise<ContractAgreement[]> { | ||
return unpackData( | ||
this._client.authApiClient().get("/contract_agreements"), | ||
"contract_agreements" | ||
); | ||
} | ||
|
||
/** | ||
* Show a given contract | ||
*/ | ||
show(id: string): Promise<Contract> { | ||
return unpackData( | ||
this._client.authApiClient().get(`/contracts/${id}`), | ||
"contract" | ||
); | ||
} | ||
|
||
/** | ||
* Show a given contract agreement | ||
*/ | ||
showAgreement(id: string): Promise<ContractAgreement> { | ||
return unpackData( | ||
this._client.authApiClient().get(`/contract_agreements/${id}`), | ||
"contract_agreement" | ||
); | ||
} | ||
|
||
/** Create an agreement for the given contract */ | ||
createAgreement(params: CreateAgreementParams): Promise<ContractAgreement> { | ||
return unpackData( | ||
this._client | ||
.authApiClient() | ||
.post(`/contract_agreements`, { contract_agreement: params }), | ||
"contract_agreement" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export type ContractLangs = "en" | "fr"; | ||
|
||
export interface Contract { | ||
/** Unique key ID */ | ||
id: string; | ||
/** Contract kind */ | ||
kind: string; | ||
/** Version of the contract */ | ||
version: string; | ||
/** Date at which the contract starts applying */ | ||
start_date: string; | ||
/** Date at which the contract stops applying, if relevant */ | ||
end_date: string | null; | ||
/** Map of locale => url of the pdf of the contract in locale */ | ||
pdf_urls: Record<ContractLangs, string>; | ||
/** Map of locale => url of a web page of the contract in locale */ | ||
web_urls: Record<ContractLangs, string>; | ||
} | ||
|
||
export interface ContractAgreement { | ||
/** Unique key ID */ | ||
id: string; | ||
/** ID of the user who accepted the contract */ | ||
user_id: string; | ||
/** The date when the contract was accepted */ | ||
date: string; | ||
/** The locale in which the contract was accepted */ | ||
locale: ContractLangs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ContractLangs } from "../../models/auth/contracts"; | ||
|
||
export interface CreateAgreementParams { | ||
/** ID of the contract to agree to */ | ||
contract_id: string; | ||
/** Locale of the contract to agree to */ | ||
locale: ContractLangs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Contracts from "../../src/Contracts"; | ||
import { testGetter, testPost } from "../utils/http"; | ||
|
||
describe("Contracts#all", () => { | ||
testGetter( | ||
"https://auth.scalingo.com/v1/contracts", | ||
null, | ||
"contracts", | ||
(client) => { | ||
return new Contracts(client).all(); | ||
} | ||
); | ||
}); | ||
|
||
describe("Contracts#allAgreements", () => { | ||
testGetter( | ||
"https://auth.scalingo.com/v1/contract_agreements", | ||
null, | ||
"contract_agreements", | ||
(client) => { | ||
return new Contracts(client).allAgreements(); | ||
} | ||
); | ||
}); | ||
|
||
describe("Contracts#show", () => { | ||
testGetter( | ||
"https://auth.scalingo.com/v1/contracts/contract-id", | ||
null, | ||
"contract", | ||
(client) => { | ||
return new Contracts(client).show("contract-id"); | ||
} | ||
); | ||
}); | ||
|
||
describe("Contracts#showAgreement", () => { | ||
testGetter( | ||
"https://auth.scalingo.com/v1/contract_agreements/contract-id", | ||
null, | ||
"contract_agreement", | ||
(client) => { | ||
return new Contracts(client).showAgreement("contract-id"); | ||
} | ||
); | ||
}); | ||
|
||
describe("Contracts#createAgreement", () => { | ||
testPost( | ||
"https://auth.scalingo.com/v1/contract_agreements", | ||
null, | ||
{ contract_agreement: { contract_id: "my-id", locale: "es" } }, | ||
"contract_agreement", | ||
(client) => { | ||
return new Contracts(client).createAgreement({ | ||
contract_id: "my-id", | ||
locale: "es", | ||
}); | ||
} | ||
); | ||
}); |