Skip to content

Can´t set correctly SDK Instance #284

@elC0mpa

Description

@elC0mpa

Thanks for this awesome library. I am trying to mock AWS Location Services but I haven't done it yet. I am pretty sure the problem is related to the sdk instance

Here is my code:

export class AddressLocatorService {
    private _locationService: AWS.Location;
    private _getAWSPlacesPredictions: (...args: any[]) => Observable<Partial<Address>[]>;

    constructor(
        private _mapsApiLoader: MapsAPILoader,
        private _zone: NgZone,
        private _store: StoreLocation,
        private _http: HttpClient,
        private router: Router
    ) {
	this.initializeAWSLocationService();
}
    private initializeAWSLocationService() {
	const identityPoolId = environment.IDENTITY_POOL_ID
	AWS.config.region = identityPoolId.split(':')[0]
	const credentials = new AWS.CognitoIdentityCredentials({
  		IdentityPoolId: identityPoolId,
	});
	this._locationService = new AWS.Location({credentials, region: AWS.config.region});
	this._getAWSPlacesPredictions = bindCallback(this._locationService.searchPlaceIndexForSuggestions.bind(this._locationService), this._getAutocompletePredictions_callback.bind(this))
    }
}

Nos I will show you the test:

import AWSMock from "aws-sdk-mock";
import AWS from "aws-sdk";

describe("Address Locator Service", () => {
    let service: AddressLocatorService;
    beforeEach(() => {
        TestBed.configureTestingModule({
            //test bed config, doesn´t matter for the issue scope
        service = TestBed.inject(AddressLocatorService);
    });
    it("termSubject should emit correct locations and places", () => {
        AWSMock.setSDKInstance(AWS);//I am pretty sure this is the problem
        AWSMock.mock(
            "Location",
            "searchPlaceIndexForSuggestions",
            (
                params: SearchPlaceIndexForSuggestionsRequest,
                callback: Function
            ) => {
                const data: SearchPlaceIndexForSuggestionsResponse = {
                    Results: [
                        {
                            Text: "52 Tamiami Trl N, Naples, FL 34102-6201, United States",
                            PlaceId:
                                "AQAAAG0AYHn7nsi-sHbgMnoH7_xTw6j7wNCFIXY_1a0jAk1s4bFiozjIT7xmnq8qHBaL7X1tMrR30j5WUK6gqpEyWO8jMNHzBSWSelP481VwonI9ELDNXj9QS8c-LGulU1IBJnLTovC0oDacwPxWnSKgQfeQ-H5Z8zr7uEL3k7WGFujlc0lKgpajpKmMeVWlqI5K",
                        },
                    ],
                    Summary: {
                        DataSource: "Here",
                        Text: "52 tamiami",
                    },
                };
                callback(undefined, data);
            }
        );
        service.termSubject.next('52 tamiami')
        service.dataSource$.subscribe((locationsAndPlaces: Partial<Address>[]) => {
            console.log('Emitted values: ', locationsAndPlaces);
        })
    });

}

The point is that the call to searchPlaceIndexForSuggestions of LocationService is not mocked
I will appreciate any help. Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions