Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can´t set correctly SDK Instance #284

Open
elC0mpa opened this issue Mar 28, 2023 · 0 comments
Open

Can´t set correctly SDK Instance #284

elC0mpa opened this issue Mar 28, 2023 · 0 comments

Comments

@elC0mpa
Copy link

elC0mpa commented Mar 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant