@@ -213,6 +213,96 @@ describe("AssociationsService", () => {
213213 } ) ;
214214 } ) ;
215215
216+ describe ( "getCompanyAssociationByUserEmail" , ( ) => {
217+ let associationsService : AssociationsService ;
218+
219+ beforeEach ( ( ) => {
220+ sinon . reset ( ) ;
221+ sinon . restore ( ) ;
222+ associationsService = new AssociationsService ( requestClient ) ;
223+ } ) ;
224+
225+ it ( "should return 200 response with the company association" , async ( ) => {
226+ sinon . stub ( requestClient , "httpPost" ) . resolves ( { status : 200 , body : mockAssociationResource } ) ;
227+ const companyNumber = mockAssociationResource . company_number ;
228+ const userEmail = mockAssociationResource . user_email ;
229+ await associationsService . getCompanyAssociationByUserEmail ( companyNumber , userEmail )
230+ . then ( ( data ) => {
231+ expect ( data . httpStatusCode ) . to . equal ( 200 ) ;
232+
233+ const castedData : Resource < Association > = data as Resource < Association > ;
234+ expect ( castedData ) . to . exist ;
235+ const association = castedData . resource as Association ;
236+ expect ( association ) . to . exist ;
237+ expect ( association . etag ) . to . equal ( "ABC" ) ;
238+ expect ( association . id ) . to . equal ( "0123456789" ) ;
239+ expect ( association . userId ) . to . equal ( "9876543210" ) ;
240+ expect ( association . userEmail ) . to . equal ( "[email protected] " ) ; 241+ expect ( association . displayName ) . to . equal ( "John Doe" ) ;
242+ expect ( association . companyNumber ) . to . equal ( "AB123456" ) ;
243+ expect ( association . companyName ) . to . equal ( "Company Ltd." ) ;
244+ expect ( association . status ) . to . equal ( AssociationStatus . AWAITING_APPROVAL ) ;
245+ expect ( association . createdAt ) . to . equal ( "2022-03-05T11:41:09.568+00:00 UTC" ) ;
246+ expect ( association . approvedAt ) . to . equal ( "" ) ;
247+ expect ( association . removedAt ) . to . equal ( "" ) ;
248+ expect ( association . kind ) . to . equal ( "association" ) ;
249+ expect ( association . approvalRoute ) . to . equal ( ApprovalRoute . INVITATION ) ;
250+ expect ( association . approvalExpiryAt ) . to . equal ( "2022-05-05T11:41:09.568+00:00 UTC" ) ;
251+ expect ( association . links . self ) . to . equal ( "/12345" ) ;
252+ } ) ;
253+ } ) ;
254+
255+ it ( "should return 400 response" , async ( ) => {
256+ sinon . stub ( requestClient , "httpPost" ) . resolves ( mockGetResponse [ 400 ] ) ;
257+ const companyNumber = mockAssociationResource . company_number ;
258+ const userEmail = mockAssociationResource . user_email ;
259+ await associationsService . getCompanyAssociationByUserEmail ( companyNumber , userEmail )
260+ . then ( ( data ) => {
261+ expect ( data . httpStatusCode ) . to . equal ( 400 ) ;
262+ } ) ;
263+ } ) ;
264+
265+ it ( "should return 401 response" , async ( ) => {
266+ sinon . stub ( requestClient , "httpPost" ) . resolves ( mockGetResponse [ 401 ] ) ;
267+ const companyNumber = mockAssociationResource . company_number ;
268+ const userEmail = mockAssociationResource . user_email ;
269+ await associationsService . getCompanyAssociationByUserEmail ( companyNumber , userEmail )
270+ . then ( ( data ) => {
271+ expect ( data . httpStatusCode ) . to . equal ( 401 ) ;
272+ } ) ;
273+ } ) ;
274+
275+ it ( "should return 403 response" , async ( ) => {
276+ sinon . stub ( requestClient , "httpPost" ) . resolves ( mockGetResponse [ 403 ] ) ;
277+ const companyNumber = mockAssociationResource . company_number ;
278+ const userEmail = mockAssociationResource . user_email ;
279+ await associationsService . getCompanyAssociationByUserEmail ( companyNumber , userEmail )
280+ . then ( ( data ) => {
281+ expect ( data . httpStatusCode ) . to . equal ( 403 ) ;
282+ } ) ;
283+ } ) ;
284+
285+ it ( "should return 404 response" , async ( ) => {
286+ sinon . stub ( requestClient , "httpPost" ) . resolves ( mockGetResponse [ 404 ] ) ;
287+ const companyNumber = mockAssociationResource . company_number ;
288+ const userEmail = mockAssociationResource . user_email ;
289+ await associationsService . getCompanyAssociationByUserEmail ( companyNumber , userEmail )
290+ . then ( ( data ) => {
291+ expect ( data . httpStatusCode ) . to . equal ( 404 ) ;
292+ } ) ;
293+ } ) ;
294+
295+ it ( "should return 500 response" , async ( ) => {
296+ sinon . stub ( requestClient , "httpPost" ) . resolves ( mockGetResponse [ 500 ] ) ;
297+ const companyNumber = mockAssociationResource . company_number ;
298+ const userEmail = mockAssociationResource . user_email ;
299+ await associationsService . getCompanyAssociationByUserEmail ( companyNumber , userEmail )
300+ . then ( ( data ) => {
301+ expect ( data . httpStatusCode ) . to . equal ( 500 ) ;
302+ } ) ;
303+ } ) ;
304+ } ) ;
305+
216306 describe ( "searchAssociations" , ( ) => {
217307 let associationsService : AssociationsService ;
218308
0 commit comments